【发布时间】:2018-03-23 10:25:25
【问题描述】:
您好,我无法对来自 nodejs 服务器的以下多维 JsonArray 数据进行循环。
只要有更多数据进入,即使 jsonarray 的索引值也会动态增加。请帮我实现for循环以动态获取数据。
我从服务器得到的响应是:-
[
[{
"id": 3,
"user_id": 22,
"coin": "btc",
"coin_quantity": 4.24524129,
"order": 1,
"order_price": 175,
"total_amount": 742.92,
"order_type": 0,
"processed": 3.85931026,
"remaining": 0.02425852,
"status": 1,
"t_fee_inr": 125.92,
"t_fee_coin": 0,
"t_gst": 22.66,
"invoice": null,
"create_time": "2018-03-20T21:22:49.000Z",
"complete_time": null
}, {
"id": 5,
"user_id": 22,
"coin": "btc",
"coin_quantity": 2.24524129,
"order": 1,
"order_price": 174.8,
"total_amount": 392.47,
"order_type": 0,
"processed": 0,
"remaining": 2.24524129,
"status": 0,
"t_fee_inr": 0,
"t_fee_coin": 0,
"t_gst": 0,
"invoice": null,
"create_time": "2018-03-21T19:41:19.000Z",
"complete_time": null
}, {
"id": 7,
"user_id": 22,
"coin": "btc",
"coin_quantity": 0.64524129,
"order": 1,
"order_price": 174.85,
"total_amount": 112.82,
"order_type": 0,
"processed": 0,
"remaining": 0.64524129,
"status": 0,
"t_fee_inr": 0,
"t_fee_coin": 0,
"t_gst": 0,
"invoice": null,
"create_time": "2018-03-21T19:42:08.000Z",
"complete_time": null
}, {
"id": 9,
"user_id": 22,
"coin": "btc",
"coin_quantity": 0.76324129,
"order": 1,
"order_price": 174.89,
"total_amount": 133.48,
"order_type": 0,
"processed": 0,
"remaining": 0.76324129,
"status": 0,
"t_fee_inr": 0,
"t_fee_coin": 0,
"t_gst": 0,
"invoice": null,
"create_time": "2018-03-21T19:43:07.000Z",
"complete_time": null
}],
[{
"total_buy_orders": 4
}], {
"page_no": "1"
}
]
【问题讨论】:
-
@TimCastelijns 不,先生,我的问题不是解析 json 数据,我知道我的问题是针对“FOR LOOP”,因为内部数组的索引值会动态变化,否则我知道如何解析这个通过将上述情况的索引值设置为 0 来获取 android 中的数据。
-
我认为不解析是不可能的,至少你必须将它解析成json数组,然后应该可以迭代json数组对象。如果是动态数据,您可以尝试查看是否有可能检查 json 数组上的 contains 之类的内容(也许
Arrays.asList(yourArray).contains(yourValue)我猜这很有用)只是您不能迭代 String 或某些完整单元的含义,每个 json 对象 -
数组中的索引值是无关紧要的,因为你循环的是对象,而不是索引。您的问题完全是关于 json 解析的,您只是没有看到它