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: 19,631
Registered: ‎07-14-2008
My Device: Not Specified
Accepted Solution

JSON library

Since some people seem to struggle to find this, I thought it might be useful to provide a download of a JSON library. 

 

I picked up the attached in my travels, not sure where from sorry.  However from my brief search, it seems to be a download from here:

https://meapplicationdevelopers.dev.java.net/source/browse/meapplicationdevelopers/demobox/mobileaja...

with some extras.

 

I've done some testing with this library, it works for me.  But YMMV.

 

Aside: this seems like a pretty good article about using JSON.

http://java.sun.com/developer/technicalArticles/javame/json-me/

Developer
Posts: 176
Registered: ‎11-06-2008
My Device: Not Specified

Re: JSON library

[ Edited ]

There's a serious bug in the json.org package for the JSONStringer class. I found it a long time ago and submitted the fix to json.org but they ignored me.

 

Calling toString( ) on a JSONStringer instance does not return the json formatted string as the docs says, it returns some object (I forget which class, maybe a subclass of Writer if memory serves).

 

To fix this edit the StringWriter class in org.json.me package to contain this additional function.

 

 

public String toString()
{
  return (buf.toString());
}

 

 

Developer
Posts: 484
Registered: ‎07-17-2008
My Device: Not Specified

Re: JSON library

JSON is included in OS 6.0

 

You might see a conflict if you include the .jar in your project.

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

Re: JSON library

Good point, I should have said that.

 

Do you think that json.org would mind if we renamed this so the classes did not conflict?  Instead of org.json.me.*, we could use org.json.rim.*, then people could just skip the import in OS 6.0 builds.  Just a thought. 

Developer
Posts: 484
Registered: ‎07-17-2008
My Device: Not Specified

Re: JSON library

I don't know if they mind but that's pretty much what I did.  Smiley Wink

 

We don't really have much choice.

Developer
Posts: 176
Registered: ‎11-06-2008
My Device: Not Specified

Re: JSON library

Why not do a conditional compilation? Include the jar or source from json.org for OS 5 and lower builds and leave it out for builds for OS 6 and up

 

There's enough new stuff (AND NEW BUGS) in OS 6 anyway that it warrants a new build for all of my apps

New Developer
New Developer
Posts: 151
Registered: ‎01-05-2010
My Device: dev alpha c (bb10)
My Carrier: www.rzr.online.fr

Re: JSON library

> Include the jar or source from json.org for OS 5 and lower builds and leave it out for builds for OS 6 and up

 

does eclipse manage different configuration or should be it done by hand ?

 

Developer
Posts: 121
Registered: ‎05-31-2012
My Device: 9900
My Carrier: Airtel

Re: JSON library

[ Edited ]

Hello Peter,

 I am using the classes in zip attached by you for JSON parsing

I am trying to parse the following String Using new JSONObject(string);

 

{"title":"As rupee sinks, RBI to meet oil cos to discuss forex needs","fro":"Financial Times","telcast":"Renouncements","summary":"The Reserve Bank of India will meet with oil company officials in Mumbai later on Monday to discuss their foreign exchange needs, two sources with direct knowledge of the matter told Reuters.\r\n\r\nThe meeting with oil companies, which are the biggest buyers of dollars in domestic currency markets, comes as the rupee slid to a record low of 61.21 against he dollar on Monday.\r\n\r\n\\\\\\\"Various options will be discussed. Oil window has been one of the suggestions,\\\\\\\" said one of the sources on Monday.\r\n\r\nDealers have said the RBI may impose a separate window to oil companies to provide them with US dollars, reducing demand for the greenback in the spot market and thus helping ease downward pressure on the rupee. ","detail":"08-07-2013","type":"text","id":352,"name":"name"}

 

But i am getting Exception with message--

com.myapp.parser.JSONException: Unterminated string at character 323

 

Whereas when i check the json with online json format validator, its declare the string as valid json.

 

Please suggest.

 

Thanks.

Rishikesh Singh
Developer
Posts: 121
Registered: ‎05-31-2012
My Device: 9900
My Carrier: Airtel

Re: JSON library