我在從JSON對(duì)象提取值時(shí)遇到一些問(wèn)題。這是我的代碼try { JSONObject json = new JSONObject(result); JSONObject json2 = json.getJSONObject("results"); test = json2.getString("name"); } catch (JSONException e) { e.printStackTrace();}test被聲明為String。代碼運(yùn)行時(shí)顯示null。如果將鼠標(biāo)懸停json2在調(diào)試模式下,則可以看到對(duì)象中的所有值和名稱。我也試過(guò)test = json2.length();這回來(lái)了test = 0。即使將鼠標(biāo)懸停在json2對(duì)象上,我也可以讀取對(duì)象中的值。這是我將使用的JSON字符串的示例。{ "caller":"getPoiById", "results": { "indexForPhone":0, "indexForEmail":"NULL", "indexForHomePage":"NULL", "indexForComment":"NULL", "phone":"05137-930 68", "cleanPhone":"0513793068", "internetAccess":"2", "overnightStay":"2", "wasteDisposal":"2", "toilet":"2", "electricity":"2", "cran":"2", "slipway":"2", "camping":"2", "freshWater":"2", "fieldNamesWithValue":["phone"], "fieldNameTranslations": ["Telefon"], "id":"1470", "name":"Marina Rasche Werft GmbH & Co. KG", "latitude":"52.3956107286487", "longitude":"9.56583023071289" }}
如何在Android中解析JSON對(duì)象
慕田峪9158850
2019-11-14 10:19:31