在這裏,我需要這樣的JSON格式發送到服務器,我怎麼能做到這一點我已經試過很多辦法,但我不能讓這是我的格式:如何使用Gson將列表轉換爲json?
{"accountModel":[
{
"AddressLine1": "purasai",
"AddressLine2": "otteri",
"AddressLine3": "t nagar",
"CompanyGroup": "yogangroups",
"CompanyName": "yogan inc",
"IsIndividual": 1,
"IsMulitLocation": 1,
"LandLine1": "landline1",
"LandLine2": "Landline2",
"PinCode": "pincode",
"WebSiteContactEmailID": "vbbb",
"WebsiteURL": "ghb",
"company_name_id": 68,
"AccountManagerID": 185,
"CityID": 165,
"IndustryID": 4,
"RegionID": 24,
"StateID": 129
},
{
"AddressLine1": "yoh",
"AddressLine2": "f",
"AddressLine3": "",
"CompanyGroup": "uo",
"CompanyName": "vv",
"IsIndividual": 1,
"IsMulitLocation": 1,
"LandLine1": "landline1",
"LandLine2": "Landline2",
"PinCode": "pincode",
"WebSiteContactEmailID": "yg",
"WebsiteURL": "ff",
"company_name_id": 10,
"AccountManagerID": 185,
"CityID": 165,
"IndustryID": 5,
"RegionID": 24,
"StateID": 126
}
]}
我怎樣才能做到這一點!我已經使用Gson庫:
Gson gson=new Gson();
String Json=gson.toJson(listobj);
JSONObject jobj=new JSONObject();
try {
jobj.put("accountModel",Json.toString());
} catch (JSONException e) {
e.printStackTrace();
}
但我無法得到所需的格式!