JSON Array Question
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.
精彩评论