1
什麼是重組的Json與Angularjs或jQuery的最好方式..重組的Json與Angularjs或jQuery的
我得到一個JSON具有以下格式
[
{
"address":"balh",
"lat":123,
"long":456
},
{
"address":"balh",
"lat":321,
"long":543
},
{
"address":"balh",
"lat":432,
"long":333
},
{
"address":"balh",
"lat":123,
"long":456
},
{
"address":"balh",
"lat":321,
"long":543
},
{
"address":"balh",
"lat":432,
"long":333
}
]
我需要的格式是其組有三個像下面這樣..
{
"1":[
{
"address":"balh",
"lat":123,
"long":456
},
{
"address":"balh",
"lat":321,
"long":543
},
{
"address":"balh",
"lat":432,
"long":333
}
],
"2":[
{
"address":"balh",
"lat":123,
"long":456
},
{
"address":"balh",
"lat":321,
"long":543
},
{
"address":"balh",
"lat":432,
"long":333
}
]
}
你輸入JSON實際上不是有效的JSON:最外面的'{'和'}'應該是'['和']',因爲它是一個數組。假設你糾正了這個問題,你就不會重構JSON _string,你會解析它,然後操縱結果對象來創建一個新的對象,並且需要你需要的結構(如果你需要的話,你可以連續返回一個JSON字符串至)。 – nnnnnn
Ahh ..它現在已經修復..謝謝.. – MomentH
謝謝nnnnnn,我不認爲你看着Angularjs ..有一個理由這樣做,使用直接與ng-repeat json綁定.. – MomentH