如何移除如下所示的api返回的嵌套json对象,并通过以通用方式使用jquery解嵌对象来将其显示为单独的字段。这是我的json对象
"response": {
"content":
"[ {
"Id": 0,
"Name": "Some name",
"createdOnDate": "0001-01-01T00:00:00",
"keyValueList":
[
{
"Key": "key1",
"Value": "Sample Data key 1"
},
{
"Key": "key2",
"Value": "sample data key 2
] }]"这就是解嵌之后应该是什么样子。
[{
"Id": 123,
"Name": "some name",
"createdOnDate": "2013-01-22T17:02:00",
"key1": "this is my key1",
"key2": "this is my key2"
}]发布于 2013-04-08 04:16:35
这是无效的JSON。在此之前,请确保您是有效的。之后,您可以遍历这些属性并以您想要的方式设置它们。
$.each(content[0]['keyValueList'], function (k, value) {
content[0][value['Key']] = value['Value']
});
delete content[0]['keyValueList'];http://jsfiddle.net/TjQzv/3/
https://stackoverflow.com/questions/15867201
复制相似问题