var abc = {"action":"Remove",
"datatable":[
{"userid":"userid0","username":"name0"},
{"userid":"userid1","username":"name1"},
{"userid":"userid2","username":"name2"},
{"userid":"userid3","username":"name3"}
]
, "msgType":"success"};
How could I create above JSON structure in java and send it as response & at client side how could I parse it?
Use Google's gson library. It converts java objects to and from json.
I've used it and it's really good.
Simple as using springframework and mark your @Controller method with @ResponseBody to json-encode your pojos.
Also use @RequestBody to decode json back and if needed use jackson annotations to customize d/encoding
考虑使用groovy: http : //groovy.codehaus.org/gapi/groovy/json/JsonBuilder.html (虽然不会在客户端帮助您)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.