Recently, the project has always been transferred to the interface, not deep understanding is very confused, so simple to clean up and convenient for future search.
"String conversion to Object"
parse is used to parse out a JSON object from a string, such as
var str = ' {' Name ': ' Demo ', ' Age ': ' 22 '} '
Results
Json.parse (str)
Object
Age: "22"
Name: "Demo"
__proto__: Object
1.eval (' (' + str + ') '); the//eval () method executes the string (possibly the JS script) dynamically, which can easily cause system security problems.
var str= ' {' name ': ' John '} ';
var obj = eval (' (' + str + ') ');
2.parseJSON (str)
var str= ' {' name ': ' John '} ';
var obj = Jquery.parsejson (str)
3.json.parse (str)
var str = ' {' name ': ' Mady ', ' Age ': ' ';
var obj = json.parse (str);
4.jquery-json Extension Library download:http://code.google.com/p/jquery-json/
"Convert object to String"
stringify () is used to parse out strings from an object, such as
var a = {A:1,b:2}
Results
Json.stringify (a)
• "{" A ": 1," B ": 2}"
You can use the tojsonstring () or global method Json.stringify () to convert a JSON object to a JSON string.
For example:
var last=obj.tojsonstring (); Convert a JSON object to a JSON character
Or
var last=json.stringify (obj); Converts a JSON object to JSON character
alert (last);
The above is a small set to introduce the JSON parsing method Summary of all the narration, I hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!