Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parse JSON file with servlet

 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've also been using GSON because it is so simple.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic