2017-02-07 2 views
0

json 형식의 데이터를 가져오고 싶지만 가져 오는 방법을 알 수없는 앱을 개발 중입니다. 나를 안내 해줘.안드로이드에서 json 객체를 얻는 방법은 무엇입니까?

JSON 데이터 : -

{ 
    "title":"title", 
     "description":"description", 
     "icon":{ 
    "url":"<image-url>", 
      "aspectRatio":1, 
      "height":75, 
      "width":75 
}, 
    "screenshots":{ 
    "url":"<image-url>", 
      "aspectRatio":1.91, 
      "height":627, 
      "width":1200 
}, 
    "landingURL":"LandingUrl", 
     "cta":"cta", 
     "rating":"rating" 
} 
+0

당신이 시도 것을 지금까지 ?? –

+0

가능한 복제본 : http://stackoverflow.com/questions/5566669/how-to-parse-a-json-object-in-android –

답변

1

가 된 JSONObject에 응답을 넣습니다.

JSONObject jsonObject = new JSONObject(response); 

그리고 json을 구문 분석하십시오.

0
JSONObject jsonObject = new JSONObject(data); 
String title = jsonObject.getString("title"); 
String description = jsonObject.getString("description"); 
JSONObject iconObject = jsonObject.JSONObject("icon"); 

다음은 json 데이터를 구문 분석하는 방법입니다. 그러나 Gson을 사용하는 것이 더 좋습니다.

0

체크 아웃 다음 코드를

try { 
    JSONObject jsonObject = new JSONObject(response); 
    String title = jsonObject.getString("title"); 
    String description = jsonObject.getString("description"); 
    JSONObject jObj = new JSONObject("icon"); 
     if(jObj.has("url")) { 
      String url = jObj.getString("url"); 
      int aspectRatio = jObj.getInt("aspectRatio"); 
      int height = jObj.getInt("height"); 
      int width = jObj.getInt("width"); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 
    } 
관련 문제