(The lack of a) JSON parser for J2ME
by Per Liedman
In a pet project I’m spending my nights working on (hopefully more about that in a later post), I found myself in need of a JSON parser, or deserializer, for J2ME/CLDC. A bit to my surprise, I found that such a thing was not easy to find, even with the whole of the internets at my disposal.
To summarize, it appears that there has been a JSON lib for J2ME up on json.org at some point, but at least I can’t find it any longer. Also, some project on java.net is popular to link to, but come on, no download link? No pre-compiled JAR-file?
Anyway, after asking over at stackoverflow.com and getting surprisingly few answers, at least I found a link to some code that was easy enough to grab.
As some kind of attempt to give back to the community, I upload the compiled JAR from that source code here. So if you need to serialize, deserialize, marshal or unmarshal JSON from J2ME/CLDC, grab this JAR and go ahead:
- Compiled JAR: json-me.jar
Source code: json-me.tar.gzUpdated 2010-09-25: the source is now available on BitBucket
The code is most likely a copy of the one that was previously posted on json.org, and is distributed under the json.org license according to the copyright notice in the source (most importantly: “The Software shall be used for Good, not Evil.”)
As a very tiny modification, I have added the methods remove and removeAll to the class JSONArray, since I really needed them. I hope you don’t mind too much.
thanks buddy..
Thank you too.
I got errors in your precompiled jars.
I found the error at your additional method. I had to change the source-code at public method remove in JSONArray.
“myArrayList.removeElementAt(index);”
Reason maybe special j2me-jars for Sun SPOT Devices.
[...] of code on my blog is far from ideal from pretty much any perspective, I took the time and put the JSON-ME source code up on BitBucket, with all its Mercurial goodness. [...]
hi dude,
thanks its really useful for me..
Thanks,
vidhya
Hey,
I have a few questions:
1) When developing a J2ME application, the JRE version must be 1.4 or lower, right?
2) Assuming the answer to the previous question is: “true”, how can I use this JSON library? it uses ArrayList and some other stuff that I think I don’t have in the 1.4 version… what am I getting wrong??
Thanks in advance.
Thanks for the complied jar !
Thanks.