我有以下內容的JSON對象:如何重命名JSON關鍵
[
{
"_id":"5078c3a803ff4197dc81fbfb",
"email":"[email protected]",
"image":"some_image_url",
"name":"Name 1"
},
{
"_id":"5078c3a803ff4197dc81fbfc",
"email":"[email protected]",
"image":"some_image_url",
"name":"Name 2"
}
]
我想改變「_id」鍵,「身份證」,所以它會成爲
[
{
"id":"5078c3a803ff4197dc81fbfb",
"email":"[email protected]",
"image":"some_image_url",
"name":"Name 1"
},
{
"id":"5078c3a803ff4197dc81fbfc",
"email":"[email protected]",
"image":"some_image_url",
"name":"Name 2"
}
]
如何我會用JavaScript,jQuery或Ruby,Rails來做這件事嗎?
謝謝。
解析JSON,相應地修改所得到的數據結構,並且將其轉換回JSON。指針:http://stackoverflow.com/questions/4935632/how-to-parse-json-in-javascript,http://stackoverflow.com/questions/1826727/how-do-i-parse-json-with-的Ruby-on-軌,http://stackoverflow.com/questions/2295496/convert-javascript-array-to-json,http://stackoverflow.com/questions/3183786/how-to-convert-a-ruby-哈希對象到JSON。 –