This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Parse  JSON file with servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Parse  JSON file with servlet" Watch "Parse  JSON file with servlet" New topic
Author

Parse JSON file with servlet

Aditya Sirohi
Ranch Hand

Joined: Jan 05, 2010
Posts: 93

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: 93

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: 60800
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30136
    
150

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
 
wood burning stoves
 
subject: Parse JSON file with servlet
 
Similar Threads
JSON response to populate listbox
Post Does not Return new Values
Kris, on your book
How to do Stress and performance testing for Webservices API
i want to create a file in the server from the client? is it possible?