Issue 10 in json-simple: java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray

941 views
Skip to first unread message

json-...@googlecode.com

unread,
Nov 6, 2009, 5:55:18 AM11/6/09
to json-...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 10 by lamkampo: java.lang.ClassCastException:
org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray
http://code.google.com/p/json-simple/issues/detail?id=10

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/q571575199_2451.jpg","profile_url":"http://www.facebook.com/profile.php?id=571575199"}}

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.


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

json-...@googlecode.com

unread,
Nov 6, 2009, 5:59:19 AM11/6/09
to json-...@googlegroups.com

Comment #1 on issue 10 by lamkampo: java.lang.ClassCastException:
org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray
http://code.google.com/p/json-simple/issues/detail?id=10

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;

json-...@googlecode.com

unread,
Nov 8, 2009, 5:24:25 AM11/8/09
to json-...@googlegroups.com
Updates:
Status: Invalid

Comment #2 on issue 10 by fangyidong: java.lang.ClassCastException:

org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray
http://code.google.com/p/json-simple/issues/detail?id=10

From the input you provided, this is a JSONObject and the code should likes
like:

JSONObject user_obj=(JSONObject)user_obj;

Reply all
Reply to author
Forward
0 new messages