JSON 有两种结构
1:对象(JSONObject):“属性/值”得集合。
复合数组形式的json遍历:
复合数组对象形式的json遍历:
1:对象(JSONObject):“属性/值”得集合。
var json = {"name":"Jack","age":20,"id":"123456"};
for (var obj in json) {
console.log(obj+':'+json[obj]);
}
2:数组(JSONArray):由值组成的有序列表。
var json = ["Jack","Mike","Tom",20,true];
for (var i = 0; i < json.length; i++) {
console.log(json[i]);
}
复合数组形式的json遍历:
var json = [["Jack","Mike","Tom",20,true],
["Jack","Mike","Tom",20,true],
["Jack","Mike","Tom",20,true]];
for (var i = 0; i < json.length; i++) {
for (var j = 0; j < json[i].length; j++) {
console.log(json[i][j]);
}
}
复合数组对象形式的json遍历:
var json = [{"name":"Jack","age":20,"id":"123456"},
{"name":"Jack","age":20,"id":"123456"},
{"name":"Jack","age":20,"id":"123456"}];
for (var i = 0; i < json.length; i++) {
for (var j in json[i]) {
console.log(j+':'+json[i][j]);
}
}
复合对象形式的json遍历:
var json = {"josn":{"name":"Jack","age":20,"id":"123456"},
"josn1":{"name":"Jack","age":20,"id":"123456"},
"josn2":{"name":"Jack","age":20,"id":"123456"}};
for (var obj in json) {
console.log(obj+":");
for (var obs in json[obj]) {
console.log(obs+':'+json[obj][obs]);
}
}