How to parse the JSON response in Blackberry/J2ME?

Solution 1:

There is an open source JSON for J2ME API on Mobile and Embedded Application Developers Project

Also you can download JSON ME (Zip file) at JSON.org not supported anymore. But you can get it from here.

I believe you can simply copy content of json project src folder to your Blackberry project src folder, refresh it in eclipse package explorer and build it.

See for details: Using JavaScript Object Notation (JSON) in Java ME for Data Interchange

Solution 2:

I am developing a Blackberry client application and I confronted the same problem. I was searching for JSON way of parsing the response which I get from the server. I am using Eclipse plug-in for BB as IDE and it comes with BB SDK including the ones for JSON.

The easiest answer to this question is that:

Initially do not forget to use this import statement:

    import org.json.me.JSONObject;

Then assign your JSON formatted response from the server to a String variable:

    String jsonStr = "{\"team\":\"Bursaspor\",\"manager\":\"Ertuğrul Sağlam\",\"year\":\"2010\"}";

Create a JSONObject:

    JSONObject obj = new JSONObject(jsonStr);

i.e. if you want to use the value of the "team" field which is "Bursaspor" then you should use your JSONObject like this:

    obj.getString("team")

This call will return the string value which is "Bursaspor".

P.S: I inspired this solution from this site which simply explains the solution of the same problem for Android development.

http://trandroid.com/2010/05/17/android-ile-json-parse-etme-ornegi-1/

Solution 3:

When you got response string then use this code

try { 
        JSONObject jsonres = new JSONObject(jsons);
        System.out.println("Preview icon from jsonresp:"+jsonres.getString("mydata"));
    } catch (JSONException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

one thing jsons is your response string which is in json format & mydata your key of data so you can get your data from JSONObject. Thnks

Solution 4:

chek this post to find out how to get JSONME source from SVN:

http://www.java-n-me.com/2010/11/how-to-import-source-code-from-svn-to.html

Hope it helps someone.

Solution 5:

You can also try :

http://pensivemode.fileave.com/verified_json.jar

I was also looking for a jar version of json (to link along my lib) :

https://radheshg.wordpress.com/tag/json/

but it seems not portable :

Building example
C:\Program Files (x86)\Research In Motion\BlackBerry JDE 4.5.0\bin\rapc.exe  -quiet  import="C:\Program Files (x86)\Research In Motion\BlackBerry JDE 4.5.0\lib\net_rim_api.jar";lib\${PROJECT}.jar;lib\json.jar codename=example\example example\example.rapc warnkey=0x52424200;0x52525400;0x52435200 Y:\src\${PROJECT}-java.git\example\src\mypackage\MyApp.java Y:\src\${PROJECT}-java.git\example\src\mypackage\MyScreen.java
tmp3139/org/json/me/JSONArray.class: Error!: Invalid class file: Incorrect classfile version
Error while building project

http://supportforums.blackberry.com/t5/Java-Development/JSON-library/m-p/573687#M117982