js如何获取json数组的长度

JavaScript032

js如何获取json数组的长度,第1张

JSON转成对象直接拿呗。

var str = '{"dpxid":"DP_144226","count":"5","timevalue":[{"time":"1464273902796","value":"27.0"},{"time":"1464273904796","value":"28.0"},{"time":"1464273906796","value":"27.0"},{"time":"1464273908796","value":"26.0"},{"time":"1464274144796","value":"20.0"}],"error":"OK" }'

console.log("JSON length: " + str.length)

var obj = JSON.parse(str)

console.log("count is: " + obj.count)

1字符串的长度

2json拥有的属性个数

字符串长度可以通过 str.length 来获得

json拥有的属性个数,可以通过JSON.parse(str)获得js对象,然后循环遍历;