您好我无法为来自nodejs Server的以下多维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"
}
]
答案 0 :(得分:1)
你可以试试这种方式
JSONArray array = yourJsonArrayFromServer;
for(int i = 0 ; i < array.length(); i++){
// get current object with: array.getJSONObject(i)
// do something
}
如果我理解你的问题。
答案 1 :(得分:0)
var test = []; //your array
for(let key of test){
if(key instanceof Array) {
console.log('array'); //detect if its an array then do iteration
getValues(key);
}else{
console.log(key); //value to access, its an object
}
}
function getValues(key){
for(let val of key){
console.log(val); //value to access, its an object
}
}
答案 2 :(得分:0)
这将适用于使用JQuery .each()函数
$.each(json, function (key, data) {
$.each(data, function (index, data) {
console.log('index', data)
})
});
json是你的JsonArray数据