JSON parsing problem in BlackBerry

Posted by anta40 on Stack Overflow See other posts from Stack Overflow or by anta40
Published on 2010-04-01T06:16:28Z Indexed on 2010/04/01 6:23 UTC
Read the original article Hit count: 1168

Filed under:
|
|

I'm working on how to parse Twitter's JSON response using JSON-ME.

For example: [code] http://apiwiki.twitter.com/Twitter-Search-API-Method:-search foo({"results":[{"profile_image_url":"http://a3.twimg.com/profile_images/762620209/drama_queen-6989_normal.gif","created_at":"Thu, 01 Apr 2010 02:35:10 +0000","from_user":"TWEETSDRAMA","to_user_id":null,"text":"NEW Twitter Lists Widget - How to put it on your blog or site http://bit.ly/47NCi6","id":11401539152,"from_user_id":95081097,"geo":null,"iso_language_code":"en","source":"<a href="http://ping.fm/" rel="nofollow">Ping.fm</a>"}... (content truncated)[/code]

Here's my method:[code] public void parseDataFromJSON(String strjson) throws JSONException { JSONTokener jtoken = new JSONTokener(strjson); JSONArray jsoarray = new JSONArray(jtoken); JSONObject jsobj = jsoarray.getJSONObject(0);

tweeter_profile_image_url = jsobj.optString("profile_image_url"); tweeter_created_at = jsobj.optString("created_at"); tweeter_from_user = jsobj.optString("from_user"); tweeter_to_user_id = jsobj.optString("to_user_id"); tweeter_text = jsobj.optString("text"); tweeter_id = jsobj.optInt("id"); tweeter_from_user_id = jsobj.optInt("from_user_id"); tweeter_geo = jsobj.optString("geo"); tweeter_iso_language_code = jsobj.optString("iso_language_code"); tweeter_source = jsobj.optString("source") }[/code]

When I ran it on the emulator, nothing was shown, so I inspected the debugger, and the output was: status: 200 content: {"results":[{"profile_image_url":"http://a1.twimg.com/profile_images/746683548/Photo_on_2010-..... ---> OK, I got the JSON content

org.json.me.JSONException: A JSONArray text must start with '[' at character 1 of {"results":[{"profile_image_url.... ---> but somehow unable to processed it properly.

So how to parse this correctly?

© Stack Overflow or respective owner

Related posts about blackberry

Related posts about JSON