Skip to content

JSONEncoder bug on UTF-8 chars #128

Open
@darronschall

Description

@darronschall

Originally filed by alexis.a...@gmail.com on 2009-12-16T14:26:55

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/serialization/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;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions