10

I want to parse the response coming from the server in JSON format. I have done some googling but i can't find any library or jar kind of thing.

Everywhere there is provided open source code as zip file.

How can i achieve this? if there is no jar available for blackberry then how to use that open source code in my application??

Shruti
  • 1
  • 13
  • 55
  • 95

6 Answers6

9

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

Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114
  • 2
    Yes, we use the JSON ME code from json.org and it works great. Like you said, just extract the source code into your own source code tree and it will be compiled into your app. – Marc Novakowski Sep 25 '09 at 05:56
  • "download JSON ME (Zip file) at JSON.org" link is broken – paullb Jul 27 '10 at 06:42
  • Hi. Can u please provide a help of how to use it for j2me? Thanks – SoH Aug 06 '12 at 06:25
6

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/

milkersarac
  • 3,399
  • 3
  • 31
  • 31
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

mdm
  • 12,480
  • 5
  • 34
  • 53
Mr. Sajid Shaikh
  • 7,051
  • 4
  • 21
  • 35
2

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.

2

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

RzR
  • 3,068
  • 29
  • 26
2

So far JSON.simple is looking like a great viable option.

  JSONParser parser=new JSONParser();

  System.out.println("=======decode=======");

  String s="[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
  Object obj=parser.parse(s);
  JSONArray array=(JSONArray)obj;
  System.out.println("======the 2nd element of array======");
  System.out.println(array.get(1));
  System.out.println();
Andrew Grothe
  • 2,562
  • 1
  • 32
  • 48