| Author |
Parse JSON file with servlet
|
Aditya Sirohi
Ranch Hand
Joined: Jan 05, 2010
Posts: 91
|
|
Hello All,
I am trying to parse a JSON file inside a servlet. Can you tell me how do i get started. The sample of JSON file is as below:-
{ items: [
{
label: "Setting up the Environment for CI",
id: "1",
message: "Dojo is available under *either* the terms of the modified BSD " +
"license *or* the Academic Free License version",
}
]}
If i want to get the value of the message property in the JSON file, how do i get that? Also can you point to Servlet+JSON tutorials.
-Adi
|
 |
Sean Clark
Rancher
Joined: Jul 15, 2009
Posts: 377
|
|
Hey,
I recommend you don't try to do this yourself and use a java library that exists already for this. I've used the one from the site http://www.json.org/ and it would be more than useable in your situation.
Sean
|
I love this place!
|
 |
Aditya Sirohi
Ranch Hand
Joined: Jan 05, 2010
Posts: 91
|
|
Thanks Sean,
Can you get me started on this with a small example. I can pick from there.
-Adi
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56215
|
|
An example is only possible if you pick one of the libraries. Personally, I've been using Google's Gson library.
By the way, most of these libraries will require strictly valid JSON as input; which your example is not.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
|
I've also been using GSON because it is so simple.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: Parse JSON file with servlet
|
|
|