JSON is a built-in object that provides the
stringify and parse methods used to convert a JS object into a JSON-compliant string, which converts a JSON-compliant string into a JS object. The parse method is equivalent to the eval () method
var obj =json.parse (str); =
var obj = eval (' (' + str + ') '); Note: If obj is originally a JSON object, then the use of the Eval () function after conversion (even if multiple conversions) is a JSON object, but the use of the Parsejson () function is problematic (throwing a syntax exception).
Json.parse () can only handle strings in JSON form, otherwise error, while Eval () is the content of the execution string;
Case One: (JSON is Object)var json={' a ': ' AA ', ' B ': ' BB ', ' C ': ' CC '};var str=json.srtingjfy (JSON);var obj=json.parse (str); Console.log (JSON);Console.log (typeof str+ "" +str);console.log (obj); Results:
Case Two: (JSON is a string)var json=
'{
' name
': ' cxh ', ' sex ': ' Man '}
';
//Note: The outermost is enclosed in single quotes with double quotes inside, otherwise an error var obj=json.parse (JSON); var str=json.srtingjfy (str); Console.log (typeof json);console.log (obj);Console.log (typeof str+ "" +str); Results:
Js Operation JSON