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
Developer
Posts: 610
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

How to consume json web service and display in a list

Hi. I am making an OS7 app using Java. I am very new to Java and need guidance on how to get my app to work.

 

Here's how my app should work.

 

1. User enters some input and presses a button (know this)

2. Input is passed to and appended to url (not sure)

 

Basically, I need to make calls to a web service at a URL http://www.whatever.com/dosomething/userinput. This URL spits out json. Then I need to take the json

 

3. Need to parse reponse and put it into a simple list

 

Do any of you have sample code on how to make calls to 3rd party web services that spit out json and put the data into a list?

 

4. If user clicks item in list, details of the item are displayed on different screen(not sure)

Any help greatly appreciated.

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

Re: How to consume json web service and display in a list

I recommend that you split this processing up into three separate functions:

 

a) Obtaining the data from the Server - create a class that is supplied the URL, connects to the Server and supplies the byte array that contains the requested data.  Networking interaction like this can be quite complicated, as evidenced by the number of Threads that discuss it on this forum.  I recommend you look at ConnectionFactory to do this, though in OS 7.0 you have some more sophisticated networking classes you can use.  Unfortunately I have not looked at these so I can't advise on their use. 

 

Type network in the Search box and review one of the networking videos to understand some of the complexities. 

 

b) Json parse this byte array.  This is pretty straight forward, this KB article should help:

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

 

c) Convert this Object to a UI.  This is probably the most complicated part, as I suspect you will find the approach rather primitive.  You will most likely be creaking a ListField, so look for samples of this.  It is a little bit tricky to get your head round first time, but work on it.

 

Good luck.