2013-08-02 1 views
1

난 내가없는 구문 분석하는 데 노력하고있어 다음과 같은 JSON은 성공했다 :이 json을 구문 분석하는 방법은 무엇입니까?

[{ 
"id":10, 
"description":"Prueba", 
"name":"Prueba", 
"price":"3.5", 
"updated_at":"2013-06-10T13:41:25Z", 
"images": 
     [{ 
      "image":{ 
       "id":6, 
       "type":"Image", 
       "description":"Prueba", 
       "name":"Prueba", 
       "data_updated_at":"2013-06-10T13:41:24Z", 
       "updated_at":"2013-06-10T13:41:25Z", 
       "position":1, 
       "data_file_size":9599, 
       "data_file_name":"tortitas.jpg", 
       "image_original":"tortitas.jpg", 
       "image_medium":"tortitas_medium.jpg", 
       "image_thumb":"tortitas_thumb.jpg" 
      } 
     }] 
}, 
{ 
"id":11, 
"description":"Tortitas ricas ricas", 
"name":"Tortitas", 
"price":"3.56", 
"updated_at":"2013-06-10T14:37:58Z", 
"images": 
     [{ 
      "image":{ 
      "id":7, 
      "type":"Image", 
      "description":"Tortitas", 
      "name":"Tortitas", 
      "data_updated_at":"2013-06-10T14:37:57Z", 
      "updated_at":"2013-06-10T14:37:58Z", 
      "position":1, 
      "data_file_size":9599, 
      "data_file_name":"tortitas.jpg", 
      "image_original":"tortitas.jpg", 
      "image_medium":"tortitas_medium.jpg", 
      "image_thumb":"tortitas_thumb.jpg" 
      } 
     }] 
    } 
}] 

내가 이름, 아이디, 가격뿐만 아니라 내가 검색없이 종료와 함께 인터넷 검색 한 모든 이미지 데이터를 얻을 필요 , 그 이유는 여기서 정상적으로 끝났기 때문입니다. 왜냐하면 이번에는 내 질문에 대한 모든 답을 찾았지만 이번에는 발견하지 못했기 때문입니다. 이것은 데이터를 파싱하는 데 사용하는 코드입니다. 이름, ID, 가격을 얻을 수 있지만 이미지가 전혀 없습니다.

JSONArray aJson = new JSONArray(sJson); 

List<Productos> prods = new ArrayList<Productos>(); 

for(int i=0; i<aJson.length(); i++) { 
     JSONObject json = aJson.getJSONObject(i); 
     Productos prod = new Productos(); 
     prod.setProduct(json.getString("name")); 
     prod.setPrice(json.getString("price")); 
     JSONArray imgsJson = json.optJSONArray("images"); 
     JSONObject images = new JSONObject(imgsJson.toString()); 
     JSONArray image = images.getJSONArray("image"); 
     for(int j = 0 ; j < image.length(); j++){ 
     JSONObject img = image.getJSONObject(i); 
     prod.setImage(img.getString("image_medium")); 
     } 
     prod.setId(Integer.valueOf(json.getString("id"))); 
     prods.add(prod); 
} 

미리 감사드립니다.

답변