Android 如何将记录从sqlite转换为Jsonobject?
这可能是一个愚蠢的问题,但我已经尽力了,我在这里无法解释我的问题,我已经从sqlite检索了所有记录,并使用Gson库进行了转换,但它正在转换为jsonarray而不是jsonobject,但我需要jsonobject发送到服务器,我如何做到这一点,让我在这里发布我的代码: 这是我检索记录的db代码:Android 如何将记录从sqlite转换为Jsonobject?,android,json,sqlite,Android,Json,Sqlite,这可能是一个愚蠢的问题,但我已经尽力了,我在这里无法解释我的问题,我已经从sqlite检索了所有记录,并使用Gson库进行了转换,但它正在转换为jsonarray而不是jsonobject,但我需要jsonobject发送到服务器,我如何做到这一点,让我在这里发布我的代码: 这是我检索记录的db代码: *public List<Model_Account> toServer() { String countQuery = " SELECT * FROM " + Mo
*public List<Model_Account> toServer() {
String countQuery = " SELECT * FROM " + Model_Account.Accunt_Table;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
List<Model_Account> listobj = new ArrayList<Model_Account>();
if (cursor.moveToFirst()) {
do {
Model_Account modelobj = new Model_Account();
modelobj.setCompany_group(cursor.getString(cursor.getColumnIndex(Model_Account.company_groups)));
modelobj.setParent_company(cursor.getString(cursor.getColumnIndex(Model_Account.Parent_company)));
modelobj.setCompany_name_id(cursor.getInt(cursor.getColumnIndex(Model_Account.companyname_id)));
modelobj.setCompany_type(cursor.getInt(cursor.getColumnIndex(Model_Account.Company_type)));
modelobj.setAddrss_line1(cursor.getString(cursor.getColumnIndex(Model_Account.Address_line1)));
modelobj.setCityid(cursor.getInt(cursor.getColumnIndex(Model_Account.CityID)));
modelobj.setPincode(cursor.getString(cursor.getColumnIndex(Model_Account.Pincode)));
modelobj.setLandline1(cursor.getString(cursor.getColumnIndex(Model_Account.Landline1)));
modelobj.setUrl(cursor.getString(cursor.getColumnIndex(Model_Account.Url)));
modelobj.setEmailid(cursor.getString(cursor.getColumnIndex(Model_Account.Email_id)));
modelobj.setIndustryid(cursor.getInt(cursor.getColumnIndex(Model_Account.IndustryID)));
modelobj.setAcm_id(cursor.getInt(cursor.getColumnIndex(Model_Account.Account_managerid)));
modelobj.setRegionID(cursor.getInt(cursor.getColumnIndex(Model_Account.regionid)));
modelobj.setMulti_location(cursor.getInt(cursor.getColumnIndex(Model_Account.mutilocationid)));
modelobj.setStateid(cursor.getInt(cursor.getColumnIndex(Model_Account.State_id)));
modelobj.setAddrss_line2(cursor.getString(cursor.getColumnIndex(Model_Account.Address_line2)));
modelobj.setAddrss_line3(cursor.getString(cursor.getColumnIndex(Model_Account.Address_line3)));
modelobj.setLandline2(cursor.getString(cursor.getColumnIndex(Model_Account.Landline2)));
listobj.add(modelobj);
}
while (cursor.moveToNext());
}
return listobj;
}
我越来越像这样了
[{"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}]
但我必须这样:
{"AccountName":"Example"}
@Yog没有向gson1提供listobj(它是在游标循环中构建的Model_Account对象的列表),可能您希望提供一个单独的Model_Account对象。不过,我不知道提供哪个Model_Account对象可以满足您的应用程序要求。也许您需要缩小SQL查询的范围,以获得想要转换为JSON格式的唯一Model_Account对象
{"AccountName":"Example"}