0
在JavaScript的/ jquery的我如何实现以下Jquery的:变换嵌套JSON对象到另一个JSON对象
old_dataset = [
{
"dob": "xyz",
"name": {
"first": " abc",
"last": "lastname"
},
"start_date": {
"moth": "2",
"day": "5",
"year": 1
},
"children": [
{
"child": {
"id": "1",
"desc": "first child"
}
},
{
"child": {
"id": "2",
"desc": "second child"
}
}
]
},
{
"dob": "er",
"name": {
"first": " abc",
"last": "txt"
},
"start_date": {
"moth": "2",
"day": "5",
"year": 1
},
"children": [
{
"child": {
"id": "1",
"desc": "first child"
}
},
{
"child": {
"id": "2",
"desc": "second child"
}
}
]
}
]
超过上述使用jQuery迭代和更改为下列
new_dataset = [
{
"dob":"xyz",
"name": <first and last name values>
"start_date":<value of month day year>,
"children": [ {
child_id :1,
child_id : 2
},
]
},{
"dob":"er",
"name": <first and last name values>
"start_date":<value of month day year>,
"children": [ {
child_id :1,
child_id : 2
},
]
}]
如果有人可以给代码转换数据,它会帮助我理解迭代
'childrens'背后的原因是什么(应该是'children'我猜,至少这是正确的英语)是一个包含一个元素的数组?我建议阅读[MDN - 使用对象](https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects)来学习如何创建和修改对象。 – 2013-02-22 12:02:24
只是一个fyi,你的json语法有一些错误。您可以使用jsonlint.com为您进行验证并进行更正。我已经做到了,正确的是http://pastebin.com/VArTyMKx – Arindam 2013-02-22 12:15:30
任何答案请 – tada 2013-02-22 14:22:42