2014-11-06 91 views
1

我想要一個JSON URL並將所有信息處理成兩個單獨的數組。數據上的第一個數組以「output_no_match」開頭,第二個數組格式相同,並以「avalanche_with_match」開頭。我被困在如何將數據分成兩個單獨的數組然後處理(並放入圖表)中。將JSON數據拆分成兩個獨立的數組

感謝您的幫助!

[{"date":"2014-12-01T00:00:00-06:00" 
"id":null 
"balance":915047.12 
"interest":710669475.15 
"interest_paid":10199.29 
"ending_principal_balance":915047.12 
"ending_interest_balance":710659275.86 
"payment_due":10199.29} 

回答

1

假設你有位於http://your-host.com/sampleData.json包含您的JSON數據文件:

$.get('http://your-host/sampleData.json').success(function(data){ 
    //data is js object with your arrays 
}); 

{"output_no_match": [{ 
    "date": "2014-12-01T00:00:00-06:00", 
    "id": null, 
    "balance": 915047.12, 
    "interest": 710669475.15, 
    "interest_paid": 10199.29, 
    "ending_principal_balance": 915047.12, 
    "ending_interest_balance": 710659275.86, 
    "payment_due": 10199.29 
}], 
"avalanche_with_match": [{ 
    "date": "2014-12-01T00:00:00-06:00", 
    "id": null, 
    "balance": 915047.12, 
    "interest": 710669475.15, 
    "interest_paid": 10199.29, 
    "ending_principal_balance": 915047.12, 
    "ending_interest_balance": 710659275.86, 
    "payment_due": 10199.29 
}]}, 

那麼你可以使用XMLHttpRequest(使用jQuery)得到它

相關問題