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