2017-01-22 20 views
-2

これは私が得ているJSONレスポンスです。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();} 
+0

それは追加して良いでしょう、あなたがこれまでのところ、私は –

+0

追加支援をしようとしている今、あなたがシャッフル – user7364693

+0

をシャッフルしたい –

答えて

0

私は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(); 
} 
関連する問題