我想将数据{"address" : "http://ebay.com"}
添加到此json数据的第二个子节点,即数据"api" : "Ebay"
的括号中。
我怎么能用jQuery做到这一点?
{"Amazon":[
{"price":"19,799.00","delivery":"FREE","api":"Amazon"},
{"price":"29,999","delivery":"FREE","api":"Ebay"}
]
}
答案 0 :(得分:2)
尝试,
var obj = {"Amazon":[ {"price":"19,799.00","delivery":"FREE","api":"Amazon"},{"price":"29,999","delivery":"FREE","api":"Ebay"} ] };
obj.Amazon[1].address = "http://ebay.com";
或使用$.merge(obj1,obj2)
功能
var obj = {"Amazon":[ {"price":"19,799.00","delivery":"FREE","api":"Amazon"},{"price":"29,999","delivery":"FREE","api":"Ebay"} ] };
$.merge(obj.Amazon[1], {
address: "http://ebay.com"
});