Example 1
In JS, convert the json format string into a JSON object, the key code
json = eval('(' str ')');
The method is as follows:
JSON application
Example 2 Using new function form
function strToJson(str){
var json = (new Function(" return " str))();
return json;
}
Example 3 Using related json2 plug-in instance
var a = ' { "name": "tom", "sex": "Male", "age": "24" }'; // String used to form json;
alert("String used to form json :【" a "】");
var b = JSON2.parse(a); //Convert string a to json format b
var c = JSON2.stringify(a); //Convert json Convert format b to string c
alert("Converted string: [" c "]");