readthefuckingmanual.net

[SOLVED] - org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray

Error added: 2009-12-19 15:10

3 solutions found.

Answer 1:

Stop trying to cast it to a JSONArray then! :)

Answer 2:

this error appear when i cast it to a JSONObject :p, but it although i didn't use JSONArray ! toc!

Answer 3:

It seems from the second example on this page http://code.google.com/p/json-simple/wiki/DecodingExamples that you are meant to be able to cast an JSONArray to an JSONObject:

String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
Object obj=parser.parse(s);
JSONArray array=(JSONArray)obj;
System.out.println(array.get(1));
  
JSONObject obj2=(JSONObject)array.get(1);
System.out.println(obj2.get("1")); 

Or am I not reading it right here?

Add an answer/solution

If you know the answer, please add your own solution below.
If you don't know, but find out later, please come back and share your answer - there will be other people struggling with this too.
There are 3 people waiting for the answer


Please enter 61948 here

If you want to be notified via email when this is solved, enter your email address here:


Hosted on a linuxvps.org Linux Virtual Private Server. Why not get your own?

Valid XHTML 1.1