js如何获取json数组的长度

2024-11-15 14:50:26
推荐回答(1个)
回答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);