1.使用eval解析
var json_t = {
'四': {
'三': {
'二': {
'2018/10/8': 8,
'2018/10/7':7
}
}
},
'DeploymentId': 4,
'Serial': 4
};
var obj = eval(json_t);
console.log(obj.四.三.二);
2.自定义遍历函数
var json_t = {
'四': {
'三': {
'二': {
'2018/10/8': 8,
'2018/10/7':7
}
}
},
'DeploymentId': 4,
'Serial': 4
};
function GetValues(numcourse,secondKey,thirdKey){
var obj = eval('json_t.'+secondKey);
console.log(obj);
var cc = eval('obj.'+thirdKey);
console.log(cc);
var json = obj.secondKey;
var values=[];
for(var key in json){
values.push(json[key]);
}
console.log(values);
return values;
}
console.log(GetValues(json_t,'四','三'));
3.查看变量属于哪种类型
typeof secondKey
4.取json中的key,value
for (var key in json_t)
{
key; ----key
json[key]; -----value
}