Mohsin26 / as3corelib

Automatically exported from code.google.com/p/as3corelib
0 stars 0 forks source link

JSONEncoder bug on UTF-8 chars #132

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. var enc:String = JSON.encode( "éè" );

What is the expected output? What do you see instead?

Expected: "\u00e9\u00e8"
Encoder doesn't produce accurate json notation 

Please use labels and text to provide additional information.

Simply replace:
http://code.google.com/p/as3corelib/source/browse/trunk/src/com/adobe/serializat
ion/json/J
SONEncoder.as#163

By

if ( ch < ' '  || ch > '}' ) {
    // get the hex digit(s) of the character (either 1 or 2 digits)
    var hexCode:String = ch.charCodeAt( 0 ).toString( 16 );

    // ensure that there are 4 digits by adjusting
    // the # of zeros accordingly.
    while( hexCode.length < 4 )
    {
        hexCode = "0"+hexCode;
    }
    // create the unicode escape sequence with 4 hex digits
    s += "\\u" + hexCode;
} else {

    // no need to do any special encoding, just pass-through
    s += ch;

}

Original issue reported on code.google.com by alexis.a...@gmail.com on 16 Dec 2009 at 2:26