mmlemon / as3corelib

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

JSONEncoder adds extra quotation marks #64

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. trace(new JSONEncoder("myString").getString())

What is the expected output? 
myString

What do you see instead?
\"myString\"

What version of the product are you using? On what operating system?
3/9/2007 build

Please provide any additional information below.

The code below works but I'm sure there is a better way to accomplish this.
I just needed a quick fix.

/**
         * Gets the JSON string from the encoder without quotes around the
resulting json string.
         *
         * @return The JSON string representation of the object
         *      that was passed to the constructor with no beginning or end quotes
         * @langversion ActionScript 3.0
         * @playerversion Flash 9.0
         * @tiptext
         */
        public function getPureString():String{
            var tempJSON:String = getString();
            if(tempJSON.charAt(0) == '"') tempJSON = tempJSON.substr(1,
tempJSON.length);
            if(tempJSON.charAt(tempJSON.length-1) == '"') tempJSON =
tempJSON.substr(0, tempJSON.length-1);
            return tempJSON;
        }

Original issue reported on code.google.com by johncbla...@gmail.com on 8 Aug 2008 at 5:48

GoogleCodeExporter commented 8 years ago
This isn't a bug per json.org.  When you encode a string in JSON, the resulting
output is a value enclosed in double-quotes.

"myString" is valid JSON
myString is not

Original comment by darron.schall on 23 Oct 2008 at 1:24

GoogleCodeExporter commented 8 years ago
Well if you're encoding json then calling getString() I expect an actual string 
not a
string with quotes around it because that that point if I send it to the server 
as a
string the server has extra quotes so saving the json now includes extra quotes.

See what I mean? I 100% get your point but sending to the server can be a pain, 
as
well as a few other things.

Original comment by johncbla...@gmail.com on 23 Oct 2008 at 5:23