我的JSON字符串:
[{ "foo":"bar", "foo2":"[{ "test":"test", "test2":"test2" }]" }]
我想将foo2
的值作为新的JSON字符串。
我尝试了以下代码,但无法正常工作:
myObj[1]["test"];
答案 0 :(得分:1)
您必须先获取foo2,然后从foo2 myObj [0] ['foo2'] [0] [“ test”];中进行测试;
答案 1 :(得分:0)
将foo2的值作为新的JSON字符串
var myObj = [{
"foo": "bar",
"foo2": '[{ "test":"test", "test2":"test2" }]' /* replaced enclosing quotes " with ' */
}];
console.log(myObj[0]['foo2']); /* replaced 1 with 0 */
答案 2 :(得分:0)
var obj = [{
"foo": "bar",
"foo2": '[{ "test":"test", "test2":"test2" }]'
}];
var foo2 = JSON.parse(obj[0]['foo2']);
console.log(foo2[0]['test']);