JSON string converted to JSON object
var str = ' {' name ': ' cxh ', ' sex ': ' Man '} ';
1. Use the eval () method
The eval () function uses the JavaScript compiler to parse the JSON text and then generate the JavaScript object. You must enclose the text in parentheses in order to avoid grammatical errors.
var obj = eval (' (' + str + ') '); Convert from JSON string to JSON object
document.getElementById ("FName"). Innerhtml=obj.name
2. Using the Json.parse () method
var obj = json.parse (str); Convert from JSON string to JSON object
3. Using the $.parsejson () method
var obj = $.parsejson (str); Convert from JSON string to JSON object
4. The official JSON conversion method:
http://www.json.org/provides a json.js so that IE8 (compatibility mode), IE7 and IE6 can support JSON objects as well as their stringify () and Parse () methods;
Can get this JS on Https://github.com/douglascrockford/JSON-js, generally now use json2.js.
Then, you can read this:
Alert (Obj.name);
Alert (Obj.sex);
JSON string converted to JSON object