1
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?

0

3 Answers 3

3

Use Google's gson library. It converts java objects to and from json.
I've used it and it's really good.

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

3 Comments

I can only use json_simple-1.1.jar for JSON library as its being used earlier and I can't add more jar file in lib.Can you provide the code which does the same thing using JSONObject and JSONArray?
@Ajka It's open source. Why don't you just copy-paste the classes into your project?
@Ajka If you're already using json-simply, why don't you create the code yoursel? It's not that hard.
0

consider groovy: http://groovy.codehaus.org/gapi/groovy/json/JsonBuilder.html (won't help you on the client side though)

Comments

0

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

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.