tags:

views:

26

answers:

3

How to use jsp to get json resulting in folowing format ?

{

     "firstName": "John",

     "lastName": "Smith",

    "address": {

         "streetAddress": "21 2nd Street",

         "city": "New York",

         "state": "NY",

         "postalCode": 10021

     },

     "phoneNumbers": [

        "212 732-1234",

        "646 123-4567"

    ]

}
A: 

You can use different libraries to convert from diferent java objects to JSON

For example the library json-simple http://code.google.com/p/json-simple/

In the json-simple page you can see some examples of encoding,decoding, and JSP & AJAX with these library.

Dubas
A: 

Structure a Java object in a similar fashion and then use a serialization mechanism such as json-simple or xstream with Json Driver

for instance new XStream(new JettisonMappedXmlDriver()); xstream.toXML(object);

irfn
A: 

Got it.

Create JSONObject. Create JSONArray.

Merge.

Thanks guy. Appreciate.