Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 2
Registered: ‎02-13-2010
My Device: 8700
My Carrier: T Mobile

How To use package org.json.me in BlackBerry JDE ?

Hi

 

I need to build a JSON parser for a BlackBerry app

 

My development platform is JDE

 

Can any one please say how I can use the package provided by Json.org ?

 

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: How To use package org.json.me in BlackBerry JDE ?

[ Edited ]

Import the files from the zip file into your project.

 

Usage:

 

JSONObject jso = new JSONObject();


try {
jso.put("key1", "value1");
jso.put("key2", "value2");
} catch(JSONException je){
je.printStackTrace();
}

System.out.println(jso.toString()); // outputs: {"key1":"value1","key2": "value2"}

 

 

To read a JSON string:

 

 

try {
JSONObject jso = new JSONObject(jsonStr);
// jsonStr is your JSON string wherever you get it
// Lets pretend its {"key1": "somevalue","hasValue": true}
String key1 = jso.getString("key1");
Boolean key1 = jso.getBoolean("hasValue");

// Sky is the limit from here...

} catch (JSONException e1) {
e1.printStackTrace();
}

 

 

 

 

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
New Contributor
Posts: 2
Registered: ‎02-13-2010
My Device: 8700
My Carrier: T Mobile

Re: How To use package org.json.me in BlackBerry JDE ?

 

 

Hello Jerome

 

Thanks very much for explaining it

 

But I am not sure how I can import or refer to the JSON zip package in my project

 

The platform I am using is RIM's own platform , JDE and NOT Eclipse

 

How can I do the import in JDE please ?

 

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: How To use package org.json.me in BlackBerry JDE ?

  1. Extract from zip file
  2. Right click project in JDE
  3. Add file to project...
  4. Find and add files.
Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Contributor
Posts: 26
Registered: ‎03-21-2010
My Device: General
My Carrier: Rogers

Re: How To use package org.json.me in BlackBerry JDE ?

Hi,

 

I am trying to import JSON files into the blackberry project. But I get many errors after importing.

The JSON java files all have errors because some of the import statements in those files are invalid in blackberry project.

 

How do I properly import and use JSON files in my application? 

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: How To use package org.json.me in BlackBerry JDE ?

What errors are you getting after they are imported? Make sure the package structure reads org.json.me and has the following files in the package:

 

JSONArray.java
JSONException.java
JSONObject.java
JSONString.java
JSONStringer.java
JSONTokener.java
JSONWriter.java
StringWriter.java

 

 

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Contributor
Posts: 26
Registered: ‎03-21-2010
My Device: General
My Carrier: Rogers

Re: How To use package org.json.me in BlackBerry JDE ?

Thanks for replying!

 

I checked the package, and it had all the files. And the error still persists. I checked that the package name is properly cited too.

 

The imports still have errors.

 

For example, in JSONObject file, these imports are reported to be invalid, and I dunno why..

 

java.lang.reflect.Field; java.lang.reflect.Modifier; java.lang.reflect.Method; java.util.Collection; java.util.HashMap; java.util.Iterator; java.util.Map; java.util.TreeSet;

 

These are the inbuilt java classes, I dont understand why they are not properly configured. Is it some problem with my eclipse setting?

Developer
Posts: 77
Registered: ‎01-27-2010
My Device: Bold 9000
My Carrier: AT&T

Re: How To use package org.json.me in BlackBerry JDE ?

You're using the Java SE version of that package.  It's trying to access classes that aren't available in J2ME.  I'm looking at json.org now and it appears that they no longer have the J2ME version on their website which is odd since I downloaded it a few weeks ago.  Presumably it's just a problem with their website and they'll add the link soon.  If you send me your email I can send you the correct package.

Highlighted
Contributor
Posts: 26
Registered: ‎03-21-2010
My Device: General
My Carrier: Rogers

Re: How To use package org.json.me in BlackBerry JDE ?

My email is nick.bodd90@gmail.com

 

Thanks! Smiley Happy

 

Hope this will solve the problem. I am struggling with this for one week now.

Contributor
Posts: 26
Registered: ‎03-21-2010
My Device: General
My Carrier: Rogers

Re: How To use package org.json.me in BlackBerry JDE ?

Since too many people are mailing me about the JSON package.

 

Here it is:

 

click this link and download it

http://www.yourfilelink.com/get.php?fid=542213