我已經在這個格式返回指標數據的API:將API中的JSON數據轉換爲有用的格式?
[
{
"concept": "population",
"year": 2012,
"value": 9.5,
"country-name": "Sweden",
},
{
"concept": "education",
"year": 2012,
"value": 12,
"country-name": "Sweden",
},
{
"concept": "population",
"year": 2012,
"value": 5,
"country-name": "Norway",
},
{
"concept": "eduction",
"year": 2012,
"value": 12,
"country-name": "Norway",
}
]
在此基礎上,我通常需要組這個由國家和年份要達到這樣的:由
var data = [
{id : Sweden, population : 9.5, education: 12},
{id : Norway, population : 5, education: 12},
]
或者只是國家和年份值作爲數組:
var data = [
{id : Sweden, values : [ { year : 2012, population : 9.5, education: 12 }, {...} ]},
{id : Norway, values : [ { year : 2012, population : 5, education: 12 }, {...} ]},
]
- 什麼JS庫可以幫助管理這些常見的數據轉換?
- 你能提供一個上面的例子(使用庫或香草js)嗎?
你如何從原來的 – hindmost 2014-11-01 15:59:09