readthefuckingmanual.net

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

Error added: 2009-12-19T15:10:41Z

3 people waiting for the answer...

3 answers found.

Answer 1443 (72.72727% helpful)

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

Answer 1222 (16.666666% helpful)

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

Answer 1293 (0.0% helpful)

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

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.


Please enter 61948 here

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