gpt4 book ai didi

java - 如何为 JsonArray 数据实现 for 循环

转载 作者:行者123 更新时间:2023-12-02 11:28:34 25 4
gpt4 key购买 nike

您好,我无法对来自 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"
}
]

最佳答案

你可以试试这个方法

JSONArray array = yourJsonArrayFromServer;

for(int i = 0 ; i < array.length(); i++){
// get current object with: array.getJSONObject(i)
// do something
}

如果我很好地理解你的问题。

关于java - 如何为 JsonArray 数据实现 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49447475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com