Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

json object as input to servlet

 
sammeta Phanikumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am sending a json object as input parameter to a servlet ( as jsonobj.toString()). Now I want to read the that parameter in the servlet.

I am readin gwith req.getParameter("jsonname"). This giving me as [Objec,object].

Please help me how to form a JsonObject in the servlet with same input.

Thanks in advance. I may get this on google..but it is urgent.. please help me.

Regards,
Sammeta Phanikumar
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sammeta Phanikumar wrote:but it is urgent..

Please read this for information on why putting this in your post may actually prevent people from responding.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to convert that JSON object to a string representation. There are libraries that will do it for you.

You may want to look into http://json.org/json2.js

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it's the other way around. HTTP can only pass strings, so the parameter will need to be converted from a string representation to a corresponding Java object. There is no such thing as a "JSON object".

I've been using Google's GSON library very effectively.

As this is primarily a server-side issue, It's been moved to the Servlets forum.
 
sammeta Phanikumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replys,

But still i am not clear on this. I have just read json string as normal string input parameter using request.getParameter(). Then how can I form it as JSONObject to access that data?

Regards,
Phani
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSONObject is not a standard class. Is it a class from a library you are using?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic