如何把json数组反序列化
发布网友
发布时间:2022-04-09 16:08
我来回答
共1个回答
热心网友
时间:2022-04-09 17:38
//序列化JSON.stringify(json)
var jsonArray = [];
jsonArray.push({a:1,b:2});
jsonArray.push({a:2,b:3});
console.log('jsonArray:'+jsonArray);
console.log('jsonArray1:'+JSON.stringify(jsonArray));
//反序列化JSON.parse(json)
var a = JSON.stringify(jsonArray);
var b = JSON.parse(a);
b..push({a:3,b:4});
console.log('b:'+b);
console.log('b1:'+JSON.stringify(b));
上面的代码执行后的输出结果:
[2016-05-21 11:59:52.764] [INFO] console - jsonArray:[object Object],[object Object]
[2016-05-21 11:59:52.765] [INFO] console - jsonArray1:[{"a":1,"b":2},{"a":2,"b":3}]
[2016-05-21 11:59:52.765] [INFO] console - b:[object Object],[object Object],[object Object]
[2016-05-21 11:59:52.766] [INFO] console - b1:[{"a":1,"b":2},{"a":2,"b":3},{"a":3,"b":4}]