I am getting this response from server:
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)"
}
]
}
And I am doing this to get the values:
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();
}
But the app crashes with a null pointer exception that
05-21 12:42:04.217: W/System.err(25961): org.json.JSONException: No value for suggestions
What am I missing? Please help... Thanx
jsonResponse.getJSONObject("response").getJSONArray("suggestions");