Home>
Today, I used the json array and the json object and the json type string to convert and take values.Take a note:
1.json type string is converted to json object and value
var jsonstring="{" bar ":" property "," baz ":3}";
var jsobject=json.parse (jsonstring);// Convert to json object
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 json type string
3.json array type string is converted to json and value and json object is converted to json string
// json array type string value
var jsonstr="[{" id ":" 01 "," open ":false," pid ":" 0 "," name ":" a department "}, {" id ":" 01 "," open " :false, "pid":"0", "name":"a department"}, {"id":"011", "open":false, "pid":"01", "name":"a Department "}, {" id ":" 03 "," open ":false," pid ":" 0 "," name ":" a department "}, {" id ":" 04 "," open ":false, "pid":"0", "name":"a department"}, {"id":"05", "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")
result:
Related articles
- Simple implementation of json object and array and conversion into js object
- Detailed introduction of json object in js
- Interchange and processing skills between JSON object and String in JS
- JSON--List collection into JSON object
- Jquery method for dynamically traversing properties and values of Json object
Trends