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 Developer
Posts: 60
Registered: ‎09-23-2011
My Device: Blackberry
My Carrier: Blackberry Developer

How to do Json Parsing in Blackberry?

I am new in Blackberry Application development

Please tell me, how to get the Json responce and parse the Data?

 

I am using Blackberry os 6.0 .please ...

 

 

Thanks!!

 

Ani

New Developer
Posts: 160
Registered: ‎03-02-2011
My Device: Not Specified

Re: How to do Json Parsing in Blackberry?

Download the library from the following link where Peter strange gave a JSON library for Blackberry.

http://supportforums.blackberry.com/t5/Java-Development/JSON-library/td-p/573687

 

IF you want to develop for OS 6.0 and above you can use the APIs of RIM, check the org.json.me.* package

New Developer
Posts: 60
Registered: ‎09-23-2011
My Device: Blackberry
My Carrier: Blackberry Developer

Re: How to do Json Parsing in Blackberry?

Thank you!!

 

I am adding the org.json.me in my project but i am not understand what will be do next ?

 

Please give me detail information about Json Parsing ?

 

please...

Thanks!!

Ani

 

New Developer
Posts: 160
Registered: ‎03-02-2011
My Device: Not Specified

Re: How to do Json Parsing in Blackberry?

I suggest you start by reading the definition of JSON and understand what really is this object. Then begin by creating a JSON object and adding data to it. You can see the example for more help.

 

JSONObject object = new JSONObject();       

try {           

object.append("KEY1", "Farid");           

object.append("KEY2", "Tony");       

} catch (Exception ex) { }               

final String jsonTest = object.toString();

New Developer
Posts: 60
Registered: ‎09-23-2011
My Device: Blackberry
My Carrier: Blackberry Developer

Re: How to do Json Parsing in Blackberry?

Hello ,

 

Thanks!!

 

I have need to get json responce from webservice and then parseing the responce.

 

If you have any example related to that please give.

Please.....

 

How i am do ?

 

 

Thanks!!

 

Ani

New Developer
Posts: 160
Registered: ‎03-02-2011
My Device: Not Specified

Re: How to do Json Parsing in Blackberry?

If you are getting the request from the server as String, you'll have to make it a JSON Object and then do whatever you want with it using the classes I gave to you.

 

To transform a String to a JSON object use the following:

 

JSONTokener token = new JSONTokener(yourJSONString);               

try {            JSONObject obj = new JSONObject(token);        } catch (Exception ex) { }

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to do Json Parsing in Blackberry?

OS 6.0 includes JSON, so if you ar eonly developing for that platform and above, then you do not need to add in a library.

 

You might find this useful:

http://supportforums.blackberry.com/t5/Java-Development/Sample-Code-Implementing-JSON-in-your-applic...

New Developer
Posts: 60
Registered: ‎09-23-2011
My Device: Blackberry
My Carrier: Blackberry Developer

Re: How to do Json Parsing in Blackberry?

Hello ,

 

I am trying to get the Json responce from web service,but i am not get that  json responce.

 

Please tell me how to get Json responce from webservice?

 

If any one have a example ..

 

Please...

 

Thanks!!

 

Ani

 

 

New Contributor
Posts: 5
Registered: ‎09-05-2011
My Device: 8900
My Carrier: I'd rather not say

Re: How to do Json Parsing in Blackberry?

Hi, this is how I usually do parsing JSON;

 - I get JSON class from json.org (jsonarray.java, jsonexception.java...and all the files)

- create parser package (I name it ParserJson.java)

 

snippet of ParserJson.java

 

public String parseSingle(String json, String nameOfArray) throws JSONException{

jsoarray = new JSONArray(json);

String data;

JSONObject jsobj = jsoarray.getJSONObject(0);

data = jsobj.optString(nameOfArray);

return data;

}

 

and in my application I will call;

 

_json = new ParserJson();

userID = _json.parseSingle("the string stream of json", "name of json string key");

 

 

the result, i have userID filled with the value from "name of json string key"

hope this help.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to do Json Parsing in Blackberry?

There is no magic with getting a JSON response from a web service, it is like getting any other sort of response.  So you question should more generally be asked

"how can I get a response from a Web Service?"

The answer actually depends on what type of Web Service you are trying to access.  If you are using a normal REST type service, then you will need to issue an http connection.  If you have a SOAP service, you will need to issue some sort of SOAP request.  So what type of web service are you targeting?