0
我使用openstreetmap來獲取當前城市名稱。我發送的網址是:解析Android中的JSON,如何解析
我得到這個結果作爲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
我試過的代碼,但該地址是NULL –
也許你正在從服務中不同的反應。檢查是否將json響應(您的案例中的s值)複製到我共享的地址。你看到地址的任何價值嗎? – Devrim