This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Other Languages and the fly likes JSON+Jquery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "JSON+Jquery" Watch "JSON+Jquery" New topic
Author

JSON+Jquery

Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
Can any one have the code to use JSON in java.

IN particular I need to populate a dropdown box using JSON response from servlet.I am using JSF 1.1 and my JS Library is Jquery 1.2.6
Help me with a code.

I browsed through and found json implementations in both javascript and plain JSON ,but I need to do it from a servlet.Im using JSON Library too.

How can I do it with JSONObject,to contain all those options and its values.

Help me with a code.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Naturally enough, I usually recommend Stringtree JSON whenever anyone asks me about Java JSON code. I find it simple, fast, and robust in use.

However, if you do want to step beyond my own software, there is a list of different implementations in a wide range of languages near the bottom of the page at json.org


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
Ya,I am ready to use your plugin.But how can I accompish what I want.Its not included or specified there
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I'm not really clear on what you want to achieve.

Can you explain with an example of what information you have in the server, and how you want it to appear on the browser etc.

Thanks,
Frank.
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
Oh Sure,

Scenario:

I have an input box and a select one menu.

Based on input text i am populating selectone menu ,via ajax.

I am using Jquery GetJSON method,leave that.
In the server side,In a managed bean function i am trying to populate an ArrayList,and return it to the jquery function.I need a method to return JSONtext as my response,so that I can populate my drop down via js:ie(ajax)

My question is:

How to write code in my managed bean to return that as a JSON response.
(with option name and value embedded in the response).
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
If I understand you correctly, using Stringtree JSON it should be as simple as:



This should result in a valid JSON string such as:



Is this what you are looking for?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSON+Jquery