我使用openstreetmap获取当前城市名称。我发送的URL是:
我得到这个结果为JSON:
{"place_id":"62762024","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"90394420","lat":"52.548781","lon":"-1.81626870827795","display_name":"137, Pilkington Avenue, Castle Vale, Birmingham, West Midlands, England, B72 1LH, United Kingdom","address":{"house_number":"137","road":"Pilkington Avenue","suburb":"Castle Vale","city":"Birmingham","county":"West Midlands","state_district":"West Midlands","state":"England","postcode":"B72 1LH","country":"United Kingdom","country_code":"gb"}}
我怎么能在我的代码中使用它。
Button b = (Button) findViewById(R.id.button123);
b.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
try {
String url="http://nominatim.openstreetmap.org/reverseformat=json&lat="+currentLatitude+"&lon="+currentLongitude+"&zoom=18&addressdetails=1";
s = getJson(url);
if(s!=null){
JSONObject jObj = new JSONObject(s);
String exResult = jObj.getJSONObject("SOMETHING")//I don't know what to put here
答案 0 :(得分:0)
使用标签获取值。如:
String placeId = jObj.getString("place_id");
String licence = jObj.getString("license");
JSONObject addressJsonObject = jObj.getJSONObject("address");
String houseNumber = addressJsonObject.getString("house_number");
编辑:BTW此页面可以帮助您了解任何json字符串的结构。将json字符串复制并粘贴到那里。 http://json.parser.online.fr/
答案 1 :(得分:0)
类似的东西:
String exResult = jObj.getJSONObject("address").getString("city");