Working Json library for Javascript?

I went to http://www.json.org/js.html and downloaded json2.js thinking everything will be ok, after that the site is at the top in google search for "json javascript" - also they have this really cool url :)

So, I did a little bit of work with this and it seemed to me that it was ok, but now I am starting to have problems with it - it just won't parse some of the things that I code with the Newtonsoft JSON.NET serializer. So, perhaps seralizer.net is confused? Not the way I see it - it creates a lovely javascript string that looks like perfect json.

The problem arises when it has to encode single quote and possibly double quotes. Take a look at these examples (only parts of the complete line)

{"Id":10651,"Text":"\'69"}
{"Id":184,"Text":"13\""}

      

Am I missing something? this is part of a larger line and they are all put into a javascript variable like this

var jsonObject = '[{"Id":46,"Type":2,.....................

      

I think it should avoid single line per line to avoid conflict with my single quoted string wrapper and avoid double quote to avoid json format conflict?

So either I am doing something wrong or json2.js is not doing it right? Or yes, it's possible that the .net json is messing around - I kind of think I messed it up, but I tried to do all sorts of things to help with syntax breaking like escaping / deleting etc. Before serialization / deserialization.

+1


source to share


2 answers


Ok, I solved the problem. Actually the hint that Joel gave me in a comment on my question to try and evaluate it, instead made me think that I can trust this json, I am trying to parse / evaluate, and since I know this at the time of page creation. why not hardcode it to the webpage. AS object - no escaping quotes or anything and no evaluation and most importantly no strings: P



So, thanks to you, and you, Joel, and you are torial :)

0


source


It could be ...

http://binnyva.blogspot.com/2006/10/invalid-json.html



And if you are serializing, perhaps protect yourself by serializing to '

and from '

.

0


source







All Articles