This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSON+Jquery

 
Dishpal Bhaluja
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dishpal Bhaluja
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic