The JSON text format is syntactically the same as the code that creates the JavaScript object.
Because of this similarity, JavaScript programs can use the built-in eval () function to generate native JavaScript objects with JSON data without a parser.
JSON syntax rules:
Data in name/value pair
Data separated by commas
Curly Braces Save Objects
square brackets to save an array
JSON Name/value pair Introduction
"Name": "Zhang Fei",
"age": 23
The value of the JSON can be:
Number (integer or floating-point numbers)
String (to be included in double quotes)
Logical value (TRUE or FALSE)
Array (in square brackets)
Object (in curly braces)
The JSON-to-JavaScript object method is:
eval("(" + str + ")");
code example:
JSON and JavaScript Object conversions
JSON goto JavaScript Object
JSON to Object 1
function Jsontoobject (str) {return
eval ("+ str +"));
}
JSON-Object 2
function Strtojson (str) {
var json = (new function ("return" + str)) ();
return JSON;
}
JSON to object 3 jquery tool function
$.parsejson ()
JavaScript objects turn to JSON
JavaScript object turns JSON
function Objecttojson (o) {
var arr = [];
var FMT = function (s) {
if (typeof s = = ' object ' && s!= null) return json2str (s);
Return/^ (String|number) $/.test (typeof s)? "" + S + "'": S;
}
for (var i in O) arr.push ("' + i +" ': "+ FMT (O[i]));
Return ' {' + arr.join (', ') + '} ';
}
The above is the entire content of this article, I hope to help you, thank you for the support of cloud habitat community!