Lovelyxredxpanda / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi there
I'm new to json-simple, tried to use it to decode a json string that
encoded by PHP(it was 2-dimension array in PHP) json_encode, the string
looks like

 {"User_001":{"first_name":"xxx","last_name":"xxx","name":"xxx
xxx","uid":"1571575199","pic_square":"http://profile.ak.fbcdn.net/v230/639/72/q5
71575199_2451.jpg","profile_url":"http://www.facebook.com/profile.php?id=5715751
99"}}

but it reports error at run time:

java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to
org.json.simple.JSONArray

any idea why? thanks for any help.

Original issue reported on code.google.com by lamka...@gmail.com on 6 Nov 2009 at 10:54

GoogleCodeExporter commented 9 years ago
forgot to include the java code. here it is.

Object user = win.eval("get_user_info()"); // get JSON from javascript
Object user_obj=JSONValue.parse(user.toString());
JSONArray user_array=(JSONArray)user_obj;

Original comment by lamka...@gmail.com on 6 Nov 2009 at 10:57

GoogleCodeExporter commented 9 years ago
From the input you provided, this is a JSONObject and the code should likes 
like:

JSONObject user_obj=(JSONObject)user_obj;

Original comment by fangyid...@gmail.com on 8 Nov 2009 at 10:24