开发者

JSON Array Question

开发者 https://www.devze.com 2023-01-11 15:27 出处:网络
How to use jsp to get json resulting in folowing format ? { \"firstName\": \"John\", \"lastName\": \"Smith\",

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": [

        "2开发者_运维问答12 732-1234",

        "646 123-4567"

    ]

}


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.


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


Got it.

Create JSONObject. Create JSONArray.

Merge.

Thanks guy. Appreciate.

0

精彩评论

暂无评论...
验证码 换一张
取 消