Page 1 of 1

byte[] to string problem

Posted: 31 Aug 2016, 06:49
by scofy
When serverside send a string by byte[] to client like this:

Code: Select all

byte[] utf8 = str.getBytes("UTF-8");
and on client side i make string by function binl2rstr()

Code: Select all

 var len = param.readInt()
    if(len > 0){
        var nameData = []
        for(var i=0;i<len;i++){
            nameData.push(param.readByte())
        }
        ret.name = binl2rstr(nameData)
    } 
everything is ok,but Chinese characters are not displayed properly,how can i fix it?

Re: byte[] to string problem

Posted: 31 Aug 2016, 08:26
by Lapo
Hi,
why are you sending strings in bytes instead of just using the string type?

That way you're likely causing encoding issues. Unless there's a specific reason stick with strings and you won't have to worry about encoding.

Thanks