Hi

I have been struggling with this for some time now, and am not sure what is wrong.
I am using the org.json package

I have this json String which looks like this:

{"2009-08-04":[{"Status":"1","Description":"sdfsdf","Task Name":"task 2","TaskId":"2"},{"Status":"1","Description":"testing 3","Task Name":"testing 3","TaskId":"3"}],"2009-07-31":{"Status":"1","Description":"read POC","Task Name":"task 1","TaskId":"1"}}

As u can see the one object is actually a json array. What i wanted to do is check whether the object is a json array or an object, then display them in a table.

But while iterating through the object the objects class is a String thus making it impossible for me to check whether it is a json array or a json object.

Iterator itr = jo.sortedKeys();
while (itr.hasNext()){
      Object obj = itr.next();
      System.out.println(obj.getClass());
}

Any ideas how i can differentiate once inside the iterator?

A trip to the mall did me well :)

I was just using the wrong method i was supposed to do this:

if ((jo.get(dDate) instanceof JSONObject)){...

its working now yay :icon_smile:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.