-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?

xenteros
  • 15,586
  • 12
  • 56
  • 91
Gef
  • 11
  • 3

1 Answers1

1

Just:

Object[] objsAgain = (Object[]) j.get("objs");
shem
  • 4,686
  • 2
  • 32
  • 43
  • 1
    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. – Gef Jun 29 '16 at 08:51