-1

I have the following array of Objects put in a JSONObject:

Object[] objs=new Object[4];
objs[0]=null;
objs[1]=1234;
objs[2]="test1";
objs[3]="test2";

JSONObject j=new JSONObject();
j.put("objs", objs);

Later in the code, I will need to get this array from the JSONObject and use it.

I've tried several ways so far to get "objs" from the JSON and assign it to an Array of Objects with no luck.

Does anyone has any idea how I can do this?

2
  • Can you update your post to show what you have tried. Commented Jun 29, 2016 at 8:05
  • Would it help to use JSONArray as here: stackoverflow.com/a/18983290/2855534 ? Commented Jun 29, 2016 at 8:59

1 Answer 1

1

Just:

Object[] objsAgain = (Object[]) j.get("objs");
Sign up to request clarification or add additional context in comments.

1 Comment

That was the first thing I thought of. I tried to print the contents of this array and I was getting a NullPointerException. Finally, the reason I was getting this exception is because my first object in the array is Null and I though that the Complete array is Null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.