Wednesday, April 3, 2013

How to add an index in json data?


I have following data structure:



Class UserModel {
Long pkid;
String name;
public UserModel() {
this.pkid = new Long(1001);
this.name = "ABC";
}
}


Now I have converted this into json:



UserModel usrObj = new UserModel();
Gson gson = new Gson();
String json = gson.toJson(userObj);


So my json string is now like:



{ "pkid": 1001,
"name": "ABC" }


But I need to create the json as



{"com.vlee.ejb.UserModel": [
{ "pkid": 1001,
"name": "ABC" } ] }


I am not sure how I can add the key "com.vlee.ejb.UserModel"



.

forums.androidcentral.com

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...