diff --git a/src/com/adobe/serialization/json/JSONEncoder.as b/src/com/adobe/serialization/json/JSONEncoder.as index db69494..e9eac91 100644 --- a/src/com/adobe/serialization/json/JSONEncoder.as +++ b/src/com/adobe/serialization/json/JSONEncoder.as @@ -164,21 +164,20 @@ package com.adobe.serialization.json default: // everything else // check for a control character and escape as unicode - if ( ch < ' ' ) - { + 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. - var zeroPad:String = hexCode.length == 2 ? "00" : "000"; - + while( hexCode.length < 4 ) + { + hexCode = "0"+hexCode; + } // create the unicode escape sequence with 4 hex digits - s += "\\u" + zeroPad + hexCode; - } - else - { - + s += "\\u" + hexCode; + } else { + // no need to do any special encoding, just pass-through s += ch;