• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSON+Jquery

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
It's a tiny ad only because the water is so cold.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic