============问题描述============
{
"address": "CN|\u5e7f\u4e1c|\u6df1\u5733|None|UNICOM|None|None",
"content": {
"address": "\u5e7f\u4e1c\u7701\u6df1\u5733\u5e02",
"address_detail": {
"city": "\u6df1\u5733\u5e02",
"city_code": 340,
"district": "",
"province": "\u5e7f\u4e1c\u7701",
"street": "",
"street_number": ""
},
"point": {
"x": "114.02597366",
"y": "22.54605355"
}
},
"status": 0
}
============解决方案1============
使用android提供的JSONArray data = new JSONArray(你的字符串);,再遍历这个data,转为JSONObject jsonObject = jsonArray.getJSONObject(i);在根据字段获取值int adkind = jsonObject.getInt(字段名);
============解决方案2============
try { JSONObject jo = new JSONObject(json); int status = jo.optInt("status"); String address = jo.optString("address"); JSONObject jo_point = jo.optJSONObject("point"); String x = jo_point.optString("x"); String y = jo_point.optString("y"); JSONObject jo_content = jo.optJSONObject("content"); String content_address = jo_content.optString("address"); JSONObject jo_detail = jo_content.optJSONObject("address_detail"); String city = jo_detail.optString("city"); int code = jo_detail.optInt("city_code"); String district = jo_detail.optString("district"); String province = jo_detail.optString("province"); String street = jo_detail.optString("street"); String street_number = jo_detail.optString("street_number"); } catch (JSONException e) { e.printStackTrace(); }
============解决方案3============
[
引用 3 楼 wlianghe00 的回复:
try { JSONObject jo = new JSONObject(json); int status = jo.optInt("status"); String address = jo.optString("address"); JSONObject jo_point = jo.optJSONObject("point"); jo换成jo_content String x = jo_point.optString("x"); String y = jo_point.optString("y"); JSONObject jo_content = jo.optJSONObject("content"); String content_address = jo_content.optString("address"); JSONObject jo_detail = jo_content.optJSONObject("address_detail"); String city = jo_detail.optString("city"); int code = jo_detail.optInt("city_code"); String district = jo_detail.optString("district"); String province = jo_detail.optString("province"); String street = jo_detail.optString("street"); String street_number = jo_detail.optString("street_number"); } catch (JSONException e) { e.printStackTrace(); }
============解决方案4============
这么标准的格式,用JSONObject
时间: 2024-10-26 22:12:21