var jsonOb = { "1": "a", "2": "b", "3": "c" }; var newJson = "{\"context\":["; for (var key in jsonOb) { newJson+="{\""+key+"\":\""+jsonOb[key]+"\"},"; console.log(key + ":" + jsonOb[key]); } newJson = newJson.substring(0,newJson.length-1); newJson += "]}"; console.log(newJson); newJson = JSON.parse(newJson); for(var i in newJson.context){ for(var key in newJson.context[i]){ console.log(key +":"+newJson.context[i][key]); } }要取陣列的話自己提出來就行了
var dataArray=eval(jsonStr);for(var i in dataArray){ //TODO}
var jsonOb = { "1": "a", "2": "b", "3": "c" }; var newJson = "{\"context\":["; for (var key in jsonOb) { newJson+="{\""+key+"\":\""+jsonOb[key]+"\"},"; console.log(key + ":" + jsonOb[key]); } newJson = newJson.substring(0,newJson.length-1); newJson += "]}"; console.log(newJson); newJson = JSON.parse(newJson); for(var i in newJson.context){ for(var key in newJson.context[i]){ console.log(key +":"+newJson.context[i][key]); } }要取陣列的話自己提出來就行了