API에서 날씨 데이터를 가져 오는 Android 앱을 제작 중입니다. 그러나 API 호출 중첩 된 필드에 대해 작동하지 않습니다. 앱이 전체 JSON 데이터를 JSONObject로 가져옵니다. 그것은 단일 필드 (예 : "results")에서는 작동하지만 중첩 된 필드에서는 작동하지 않습니다. 여기 내 JSON 개체 코드는 다음과 같습니다JSONObject가 Android에서 중첩 된 필드의 값을 가져올 수없는 이유는 무엇입니까?
http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:24728&sensor=false
제발 도와주세요 :
여기JSONObject latlong = new JSONObject(json);
String lat = latlong.getInt("results.geometry.location.lat") + "";
String lng = latlong.getInt("results.geometry.location.lng") + "";
는 JSON 데이터에 대한 링크입니다!
[GSON] (https://github.com/google/gson)을 사용해 보시지 않겠습니까? 그것은 그러한 상황에서 여러분의 삶을 훨씬 쉽게 만듭니다. –