Monday, April 23, 2012

GSON: map to json string simple example


import com.google.gson.Gson;
...
...
Map<String,Object> modelMap = new HashMap<String,Object>();
modelMap.put("message", "welcome");
modelMap.put("success", false);
modelMap.put("data", new Object());                                    


Gson gson = new Gson();
String jsonOutput = gson.toJson(modelMap); // {"message":"welcome","data":{},"success":false}


Resources:
http://blog.pontt.com/json-con-java/introduccion-java-y-json-primera-parte-con-ejemplo/
http://code.google.com/p/google-gson/

No comments: