我正在從服務器這樣的響應:空指針的JSON數組的Android
status: "ok",
response: {
suggestions: [
{
suggestion: "Cetri (10 mg)"
},
{
suggestion: "Cetri-Plus (300 & 10)"
},
{
suggestion: "Cetriax (1000 mg)"
},
{
suggestion: "Cetricon (10 mg)"
},
{
suggestion: "Cetrics (500 & 5 & 5)"
}
]
}
而且我這樣做是爲了獲取值:用一個空指針異常
String result = Utils.convertInputStreamToString(inputStream);
//Printing server response
System.out.println("server response is :" + result + "\n" + inputStream);
try {
JSONObject jsonResponse = new JSONObject(result);
js=jsonResponse.getJSONArray("suggestions");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但應用程序崩潰是
05-21 12:42:04.217: W/System.err(25961): org.json.JSONException: No value for suggestions
我錯過了什麼?請幫助...感謝名單
看起來像是缺少「{」 – inmyth
是JSON的響應部分? 'jsonResponse.getJSONObject(「response」)。getJSONArray(「suggestions」);' – Anirudha
首先在任何在線json解析器網站(https://www.jsoneditoronline.org/)檢查你的json字符串 – Pankaj