2016-07-13 2 views
0

related_ids 배열의 데이터를 검색하려고하지만 실패합니다. 내 코드는 배열의 각 값을 따로 제공하지 않습니다.json을 통해 배열 데이터 검색

{ 
    "title": "Prod" 
    "related_ids": [3] 
    0: 4323 
    1: 4321 
    2: 4317 
    "tags": [0] 
    } 

이것은 내 코드입니다.

JSONArray jsonArray = response.getJSONArray("showProductListResponse"); 

    for (int i = 0; i < jsonArray.length(); i++) { 
     try { 
      JSONObject obj = jsonArray.getJSONObject(i); 
      HomelList productListItems = new HomelList(); 

      productListItems.setName(obj.getString("title"));          

      try { 
       JSONArray relatedimages = obj.getJSONArray("related_ids"); 
       for (int j = 0; j < relatedimages.length(); j++) { 
        JSONObject relimagesObject = relatedimages.getJSONObject(j); 
        productListItems.setRelatedids(relimagesObject.getInt(relimagesObject.indexOf[j]); 
       } 
      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 

      gavkidata.add(productListItems); 
      adapter.notifyDataSetChanged(); 

     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
    } 

답변

0

JSON 데이터가 유효하지 않습니다.

는 나는이

{ 
    "title": "Prod", 
    "related_ids": [ 
    4323, 
    4321, 
    4317 
    ], 
    "tags": [] 
} 

과 같아야 또는 related_ids 포함해야하는 경우 객체가이

{ 
    "title": "Prod", 
    "related_ids": [ 
    {0: 4323}, 
    {1: 4321}, 
    {2: 4317} 
    ], 
    "tags": [] 
} 
처럼 변경할 생각