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

标签 javascript jquery arrays ajax json

我正在尝试获取 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/

相关文章:

带有事件参数的 Javascript setTimeout 函数调用?

javascript - 根据数组中的对象属性生成带头的列表

javascript - 根据用户输入引用类中的不同对象

javascript - 在没有 sdk 的情况下导入 Firefox 扩展中的内容脚本

javascript - 我如何在 React Native 中解析 HTML 文件?

javascript - 无法从 kendotreelist 中的 kendo 模板调用 typescript 中的函数

javascript - 如何在 if 语句返回 false 的情况下中止 jquery 函数

javascript - 使用 AngularJS 中的指令更改值输入 AngularJS

c - 只打印 ARRAY[i][j] 不打印 ARRAY[j][i].... 删除二维数组的对角元素

javascript - 如何在 JavaScript 中使用此数组格式返回正确的值?