Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  163] [ 3]  / answers: 1 / hits: 86600  / 15 Years ago, thu, april 2, 2009, 12:00:00

I'm trying to figure out what's gone wrong with my json serializing, have the current version of my app with and old one and am finding some surprising differences in the way JSON.stringify() works (Using the JSON library from json.org).



In the old version of my app:



 JSON.stringify({a:[1,2]})


gives me this;



{a:[1,2]}


in the new version,



 JSON.stringify({a:[1,2]})


gives me this;



{a:[1, 2]}


any idea what could have changed to make the same library put quotes around the array brackets in the new version?


More From » json

 Answers
3

Since JSON.stringify has been shipping with some browsers lately, I would suggest using it instead of Prototype’s toJSON. You would then check for window.JSON && window.JSON.stringify and only include the json.org library otherwise (via document.createElement('script')…). To resolve the incompatibilities, use:



if(window.Prototype) {
delete Object.prototype.toJSON;
delete Array.prototype.toJSON;
delete Hash.prototype.toJSON;
delete String.prototype.toJSON;
}

[#99758] Friday, March 27, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominiqued

Total Points: 189
Total Questions: 122
Total Answers: 103

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
dominiqued questions
;