Today, we use the JSON array and JSON object and JSON type string to transfer and value each other, recording:
1.json types of strings converted to JSON objects and values
1 var jsonstring = ' {' Bar ': ' Property ', ' Baz ': 3} '; 2 var jsobject = Json.parse (jsonstring); Convert to JSON object 3 alert (jsobject.bar); Take the value in JSON
2.json object to JSON type string
var jsonstring = ' {' Bar ': ' Property ', ' Baz ': 3} '; var jsobject = Json.parse (jsonstring); Convert to JSON object alert (Jsobject.bar); Take the value in JSON var st = json.stringify (jsobject); Convert to a JSON-type string
string conversion of 3.json array types to JSON and values and JSON objects to convert to JSON strings
JSON array type string value var jsonstr = ' [{' id ': "" "," "open": false, "pid": "0", "name": "A department"},{"id": "A", "open": false, "pid": "0", "Name": "A department"},{"ID": "011", "open": false, "pid": "The", "name": "A department"},{"ID": "The", "open": false, "pid": "0", "name": "A Department" },{"id": "OK", "open": false, "pid": "0", "name": "A Department"}, {"id": ",", "open": false, "pid": "0", "name": "A Department"}, {"id": "06", " Open ": false," pId ":" 0 "," name ":" A Department "}] '; var jsonobj = Json.parse (JSONSTR);//Convert to JSON object for (Var i=0;i< jsonobj.length;i++) { alert (jsonobj[i].id); Take the value in JSON}console.log (jsonobj) var jsonStr1 = json.stringify (jsonobj) console.log (jsonstr1+ "JSONSTR1")
Results:
JSON-Object JSON-string cross-transfer and value in JavaScript