将JSON数据拆分为两个单独的数组

时间:2014-11-06 16:35:48

标签: javascript jquery arrays ajax json

我试图获取JSON网址并将所有信息处理成两个单独的数组。数据上的第一个数组以" output_no_match"开头,第二个数组格式相同,以" 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}

1 个答案:

答案 0 :(得分:1)

假设您的文件位于http://your-host.com/sampleData.json,其中包含您的JSON数据:

{"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)来获取它:

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