[英]JSON data parsing android
This is JSON response I am getting.这是我得到的 JSON 响应。
I want to select first 45 records response then I want to select next 45 and so on.我想选择前 45 条记录响应然后我想选择下 45 条等等。
How can I parse this data?我该如何解析这些数据?
Help.帮助。
{
"data": [
{
"id": "xxxxx"
},
{
"id": "xxxxx"
}
]
}
Something like this I am trying.我正在尝试这样的事情。
try {
JSONObject rob = response.getJSONObject();
JSONArray array = rob.getJSONArray("data");
for(int i=0;i<array.length();i++){
JSONObject friend = array.getJSONObject(i);
Log.d("uid",friend.getString("id"));
}
} catch (JSONException e) {e.printStackTrace();}
I wrote it without any IDE, it just is an idea and not more.我在没有任何 IDE 的情况下编写它,它只是一个想法而不是更多。 You will need to check and write it correctly.
您需要检查并正确书写。
// Fields
final static int ITEMS_PER_REQUEST = 45;
int currentIndex = 0;
// Method body
try {
JSONObject rob = response.getJSONObject();
JSONArray array = rob.getJSONArray("data");
int size = Math.min(array.Length, currentIndex + ITEMS_PER_REQUEST);
while(currentIndex < size;) {
JSONObject friend = array.getJSONObject(currentIndex);
Log.d("uid",friend.getString("id"));
++currentIndex;
}
} catch (JSONException e) {
e.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.