Hi,
How to parse special characters in json in jquery...?
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Varsha BPosted Sep 6, 2014, 6:49 AM
Varsha BPosted Sep 6, 2014, 3:04 AM
{"Id":1,"Name":"!#$%'()*+,-/:;=?@[]^_`{|}~0000&<> !#$%'()*+,-/:;=?@[]^_`{|}~0000&<> !#$%'()*+,-/:;=?@[]^_`{|}~0000&<> ABCDE"}
This above json is working fine.
But coming to, {"Id":2,"Name":"\} , it is not working.
How to parse "\ these two special characters.
thanks
Ramesh MaruthiPosted Sep 5, 2014, 10:37 AM
Use square bracket notation instead :
Example :
var string = "{\"parse\":{\"title\":\"Wiki\",\"revid\":491629701,\"text\":{\"*\":\"Text\"}}}";
var json = $.parseJSON(string);
console.log(json.parse.text["*"]);
Once look at this links to :
http://stackoverflow.com/questions/4253367/how-to-escape-a-json-string-containing-newline-characters-using-javascript
http://www.sencha.com/forum/showthread.php?56528-Handling-JSON-with-special-characters
http://stackoverflow.com/questions/10133082/escape-all-special-characters-in-a-string-that-is-sent-by-jquery-ajax
http://united-coders.com/christian-harms/the-art-of-escaping-described-examples-and-worst-test-data/