0

I need to parse a JSON string in my project, which runs on BB OS 5. OS version 5 does not have JSON parsing inbuilt in it. I have tried the code from the Knowledge Base article Sample Code - Implementing JSON in your application, but it does not run on OS 5 either.

Can someone suggest a library or some jar file to parse JSON for BB OS 5.

Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
Hades
  • 75
  • 1
  • 12
  • 1
    first take the jar file from this below link https://github.com/upictec/org.json.me/tree/master/src/main/java/org/json/me which is provided by @Signature and add to your project. Implement like in 6.0 – alishaik786 Jun 14 '12 at 05:48
  • Searching StackOverflow for "+blackberry +json" turns up a number of similar questions already answered. Among them: http://stackoverflow.com/questions/7453618/json-parser-for-blackberry-os-5 http://stackoverflow.com/questions/7288204/reading-json-on-blackberry-os-pre-6-0 – Michael Donohue Jun 16 '12 at 20:11

2 Answers2

2

This will help you - Json

 String jsonStr = "{\"team\":\"india\",\"manager\":\"meSağlam\",\"year\":\"2012\"}";

Create a JSONObject:

JSONObject obj = new JSONObject(jsonStr);

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 "india".

Rince Thomas
  • 4,158
  • 5
  • 25
  • 44
  • Hi Signare.. Your above code will work fine for BB OS 6 and above, But it gives an error on OS 5 on launch, saying Module 'net_rim_json_org' not found. I need to run it on BB OS ver 5. – Hades Jun 14 '12 at 06:53
  • if you need the jar file, then i will email you. – Rince Thomas Jun 14 '12 at 07:08
  • I tried the above code and tested it on simulators, it works for OS6 simulator, but not for OS 5 simulator. Are you sure you did not import any library or package for JSON parsing? – Hades Jun 14 '12 at 07:12
  • i used the json-me.jar library. – Rince Thomas Jun 14 '12 at 07:13
  • hey buddy.. sorry to bug u again... I imported the jar file in my project, but when I run the project it gives me an error Error!: Duplicate definition for 'org.json.me.JSONArray' found in: org.json.me.JSONArray – Hades Jun 14 '12 at 08:50
  • remove the json classes. only import the jar file – Rince Thomas Jun 14 '12 at 08:52
  • but above my class I have to import import org.json.me.JSONException; import org.json.me.JSONObject; – Hades Jun 14 '12 at 09:00
  • you added https://github.com/upictec/org.json.me/tree/master/src/main/java/org/json/me the java files to your project ? – Rince Thomas Jun 14 '12 at 09:04
  • I had added it initially, but it dint work. So now I do not have it in my source.. – Hades Jun 14 '12 at 09:06
1

Hey thanks Signare for your help. The jar dint work for me but importing the source files did. :) Initially I had imported the source files, but along with that I forgot to remove the BB json imports. Now it works fine... on all OS versions.

Got the source files from here https://bitbucket.org/liedman/json-me/src/501a54188df3/src/org/json/me

Hades
  • 75
  • 1
  • 12