Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSON数据解析_Java_Json - Fatal编程技术网

Java JSON数据解析

Java JSON数据解析,java,json,Java,Json,这是我得到的JSON响应 我想先选择前45条记录,然后再选择下45条记录,依此类推 如何解析这些数据 救命啊 { "data": [ { "id": "xxxxx" }, { "id": "xxxxx" } ] } 像这样的我正在尝试 try { JSONObject rob = response.getJSONObject(); JSONArray array = rob.getJSONArray("data

这是我得到的JSON响应

我想先选择前45条记录,然后再选择下45条记录,依此类推

如何解析这些数据

救命啊

{
  "data": [
    {
      "id": "xxxxx"
    },
    {
      "id": "xxxxx"
    }
  ]
}
像这样的我正在尝试

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();}
试试看{
JSONObject rob=response.getJSONObject();
JSONArray数组=rob.getJSONArray(“数据”);

对于(inti=0;i我在没有任何IDE的情况下编写了它,它只是一个想法,而不是更多。您需要检查并正确编写它

// 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();
}
//字段
每个请求的最终静态整数项=45;
int currentIndex=0;
//方法体
试一试{
JSONObject rob=response.getJSONObject();
JSONArray数组=rob.getJSONArray(“数据”);
int size=Math.min(array.Length,currentIndex+每个请求的项);
while(currentIndex
最好添加,到目前为止您尝试了什么添加了帮助我想shufflenow您所说的shufflemeans是什么意思首先是45然后是45。您可以将
I
作为全局变量,第一次从
0
开始,直到循环中的
45
,下次从
45
开始,依此类推