Java 如何为JsonArray数据实现for循环
您好,我无法对来自nodejs服务器的以下多维JsonArray数据执行循环 即使是jsonarray的索引值也会在有更多数据进入时动态增加。请帮助我实现for循环以动态获取数据 我从服务器得到的响应是:-Java 如何为JsonArray数据实现for循环,java,arrays,json,for-loop,Java,Arrays,Json,For Loop,您好,我无法对来自nodejs服务器的以下多维JsonArray数据执行循环 即使是jsonarray的索引值也会在有更多数据进入时动态增加。请帮助我实现for循环以动态获取数据 我从服务器得到的响应是:- [ [{ "id": 3, "user_id": 22, "coin": "btc", "coin_quantity": 4.24524129, "order": 1, "order_pr
[
[{
"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
}
如果我能很好地理解您的问题。这将对您使用JQuery函数有效
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
}
}
json是您的JsonArray数据@TimCastelijns不,先生,我的问题不是解析json数据,我知道我的问题是for循环,因为内部数组的索引值将动态变化,否则我知道如何在android中解析此数据,将索引值0放入上述情况。我认为不解析是不可能的,至少您必须将其解析为json数组,然后应该可以迭代json数组对象。对于动态数据,您可以尝试查看是否有可能检查json数组上的包含,可能是arrays.asListyourArray.containsyourValue,我想可能很有用,因为您不能在字符串或其他完整单元上进行迭代,每个json对象数组中的索引值都是无关的,因为您在对象上循环,而不是在索引上循环。你的问题完全是关于json解析的,你只是看不到ITI,我猜他想用java来解决它,他只是从节点获取数据:
$.each(json, function (key, data) {
$.each(data, function (index, data) {
console.log('index', data)
})
});