我正在尝试获取 JSON url 并将所有信息处理到两个单独的数组中。数据上的第一个数组以“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}
最佳答案
假设您有一个文件位于 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
});
关于javascript - 将 JSON 数据拆分为两个单独的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26784611/