1. Json.parse (jsonstring): Parsing a JSON object in a string
var str = ' [{' href ': ' baidu.com ', ' text ': ' Test ', ' OrgID ': 123, ' dataType ': ' Curry ', ' activeclass ': ' Haha '}] ';
Json.parse (str);
Results:
2 json.stringify (obj): Converts a JSON object to a string
var obj = [{"href": "baidu.com", "text": "Test", "OrgID": 123, "DataType": "Curry", "activeclass": "haha"}];
Json.stringify (obj);
Results:
' [{' href ': ' baidu.com ', ' text ': ' Test ', ' OrgID ': 123, ' dataType ': ' Curry ', ' activeclass ': ' Haha '}] '
3. Jquery.parsejson (jsonstring): Converts a well-formed JSON string to its corresponding JavaScript object
var str = ' [{' href ': ' baidu.com ', ' text ': ' Test ', ' OrgID ': 123, ' dataType ': ' Curry ', ' activeclass ': ' Haha '}] ';
Jquery.parsejson (str);
Results:
The difference between 4.json.parse () and Jquery.parsejson ():
Some browsers do not support the Json.parse () method, and when the Jquery.parsejson () method is used, the results of the Json.parse () method are returned when the browser is supported, or the results of a similar implementation of the Eval () method are returned, as the above conclusions refer to jquery 1.9.1 concluded:
Parsejson:function (data) {
//attempt to parse using the native JSON parser the-A-
window. JSON && windows. Json.parse) {return
window. Json.parse (data);
}
if (data = = null) {return
data;
}
if (typeof data = = "string") {
//Make sure leading/trailing whitespace is removed (IE can ' t handle it)
data = Jquery.trim (data);
if (data) {
//Make sure the incoming data are actual JSON
//Logic borrowed from http://json.org/json2.js
if (Rvalidchars.test data.replace (Rvalidescape, "@")
. Replace (Rvalidtokens, "]")
. Replace (rvalidbraces , "")) {return
(the new Function ("return" + Data)) ();
}} Jquery.error ("Invalid JSON:" + data);
},
The above article about Json.parse (), Json.stringify (), Jquery.parsejson () is the use of small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.