File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
Similar Threads
Iterating a JSON in jQuery
ajax call using jquery, json, struts
Java Representation of JSON String
JSON Object and Java Script DropDown
JSON response to populate listbox