1

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"

    ]

}
3
  • Welcome to StackOverflow. You can format source code with the "101010" toolbar button. I've done it for you this time. Commented Aug 11, 2010 at 8:00
  • What form is the input data in? Commented Aug 11, 2010 at 8:16
  • Your question is pretty vague. Normally don't use a JSP at all to "get" JSON. A smart guy would just have printed the above string as-is. So there must be more into the story. What exactly is the functional requirement? Where does the data come from? Where should the data go? Who should request the data? What are the business conditions? It now much sounds like you're using/choosing the wrong tools for the job. Commented Aug 11, 2010 at 11:33

3 Answers 3

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

0

Got it.

Create JSONObject. Create JSONArray.

Merge.

Thanks guy. Appreciate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.