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:

  • Previous Detailed explanation of the exception handling mechanism in C ++
  • Next Solve the problem that AngualrJS page refresh causes abnormal display
  • Trends