我有一个数组列表和一个独立的字符串。我想将它们转换成JSON格式,并期望以下JSON格式。
期望的格式,
我用了这种方式,但是不正确。
请帮忙。
期望的格式,
{
"last_sync_date": "2014-06-30 04:47:45",
"recordset": [
{
"contact_group": {
"guid": "y37845y8y",
"name": "Family",
"description": "Family members",
"isDeleted": 0
}
},
{
"contact_group": {
"guid": "gt45tergh4",
"name": "Office",
"description": "Office members",
"isDeleted": 0
}
}
]
}
我用了这种方式,但是不正确。
public void createGroupInServer(Activity activity, String lastSyncDateTime, ArrayList<ContactGroup> groups)
throws JSONException {
// create json object to contact group
JSONObject syncDateTime = new JSONObject();
syncDateTime.putOpt("last_sync_date", lastSyncDateTime);
JSONArray jsArray = new JSONArray("recordset");
for (int i=0; i < groups.size(); i++) {
JSONObject adsJsonObject = new JSONObject("contact_group");
adsJsonObject = jsArray.getJSONObject(i);
adsJsonObject.put("guid", groups.get(i).getGroupId());
adsJsonObject.put("name", groups.get(i).getGroupName());
adsJsonObject.put("isDeleted", groups.get(i).getIsDeleted());
}
请帮忙。