例如json格式如下:
{
"status":"OK",
"result":{
"location":{
"lng":116.322987,
"lat":39.983424
},
"formatted_address":"北京市海淀区中关村大街27号1101-08室",
"business":"中关村",
"addressComponent":{
"city":"北京市",
"district":"海淀区",
"province":"北京市",
"street":"中关村大街",
"street_number":"27号1101-08室"
},
"cityCode":131
}
}
解析方式如下:
JSONObject jobject = new JSONObject(resulta);
String status = jobject.getString("status");
JSONObject result = jobject.getJSONObject("result");
JSONObject location = result.getJSONObject("location");
JSONObject addressComponent = result.getJSONObject("addressComponent");
String lng = location.getString("lng");
String lat = location.getString("lat");
String formatted_address = result.getString("formatted_address");
String business = result.getString("business");
String city = addressComponent.getString("city");
String district = addressComponent.getString("district");
String province = addressComponent.getString("province");
String street = addressComponent.getString("street");
String street_number = addressComponent.getString("street_number");
String cityCode = result.getString("cityCode");