0

I am trying to get a single string from a JSON response.("oppdatert")

The following line is returned when i run my function:

{"isError":false,"errorMsg":null,"response":{"oppdatert":"ja"}}

This is an async-task, and under onTaskComplete i have the following code:

String approved = null;
JSONArray myJsonArray = JSONreturn.getJSONArray("response");

myList.clear();

for(int i = 0; i < myJsonArray.length(); i++) {

     JSONObject brukerOppdatert = myJsonArray.getJSONObject(i);
     approved = brukerOppdatert.getString("oppdatert");

The application crashes after "JSONArray = myJsonArray = ..."

This method have worked on other json-array, but the difference is that in the past there have been more then one object.

any ideas?

Toby
  • 53
  • 7

1 Answers1

1

First of all your response is JSONObject not JSONArray. so

JSONObject myJsonobject = JSONreturn.getJSONObject("response");

myList.clear();

myJsonobject.getString("oppdatert");

So

myJsonobject.getString("oppdatert")

this will get you, your required string.

Tejas Pandya
  • 3,987
  • 1
  • 26
  • 51