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