解析Json数据OSM

时间:2018-08-10 13:12:43

标签: android json openstreetmap

我正在创建一个应用程序,以获取Google没有地理编码的地址。我从OSM(openstreetmap)找到了json数据,这是链接https://nominatim.openstreetmap.org/reverse?format=json&lat=-7.740601&lon=110.3333017&zoom=18&addressdetails=1

{  
   "place_id":"234438878",
   "licence":"Data © OpenStreetMap contributors, ODbL 1.0. https:\/\/osm.org\/copyright",
   "osm_type":"way",
   "osm_id":"585612977",
   "lat":"-7.74078232331096",
   "lon":"110.333420400495",
   "display_name":"Tlogoadi, Mlati, Sleman, Daerah Istimewa Yogyakarta, 55284, Indonesia",
   "address":{  
      "county":"Tlogoadi",
      "state_district":"Sleman",
      "state":"Daerah Istimewa Yogyakarta",
      "postcode":"55284",
      "country":"Indonesia",
      "country_code":"id"
   },
   "boundingbox":[  ]
}

我的问题是如何将上述json格式的display_name(单个数据)获取到Android?

1 个答案:

答案 0 :(得分:0)

尝试一下

  try
{
    JSONObject jsonObject =新的JSONObject(response);

    字符串displayName = jsonObject.getString(“ display_name”)

    Log.e(“显示名称”,“:” + displayName);
}
捕获(JSONException e)
{
    e.printStackTrace();
}
 

输出:

”在此处输入图片描述“