这是我正在使用的json对象
{ "name": "John Smith","age": 32,"employed": true,"address": { "street": "701 First Ave.","city": "Sunnyvale,CA 95125","country": "United States" },"children": [ { "name": "Richard","age": 7 },{ "name": "Susan","age": 4 },{ "name": "James","age": 3 } ] }
我想要这个另一个键值对:
"collegeId": { "eventno": "6062","eventdesc": "abc" };
我尝试了连接,但这给我的结果与||符号和我cdnt迭代.我使用溢出,但只删除逗号.
concattedjson = JSON.stringify(JSON.parse(json1).concat(JSON.parse(json2)));
如何将密钥对值添加到现有的json对象?
我在javascript工作
解决方法
这是最简单的方式,它正在为我而工作.
var testJson = { "name": "John Smith","address": { "street": "701 First Ave.","country": "United States" },"children": [ { "name": "Richard","age": 7 },{ "name": "Susan","age": 4 },{ "name": "James","age": 3 } ] }; testJson.collegeId = {"eventno": "6062","eventdesc": "abc"};