//我將sqlite的數據轉換成JSON格式我想轉換JSON根據我的格式
嘗試
{
SQLiteDatabase db;
String dbDir= Environment.getExternalStorageDirectory()+"/"+getResources().getString(R.string.folderName);;
db=getActivity().openOrCreateDatabase(dbDir + "/" + getResources().getString(R.string.dbName), Context.MODE_PRIVATE, null);
Cursor c = db.rawQuery("select * from products", null);
Log.e("fetch_category", "" + c.getCount());
if (c.getCount() == 0)
{
}
else
{
c.moveToFirst();
JSONObject rowObject = new JSONObject();
do
{
int totalColumn = c.getColumnCount();
for(int i=0 ; i< totalColumn ; i++)
{
if(c.getColumnName(i) != null)
{
try
{
if(c.getString(i) != null)
{
Log.d("TAG_NAME", c.getString(i));
rowObject.put(c.getColumnName(i) , c.getString(i));
}
else
{
rowObject.put(c.getColumnName(i) , "");
}
}
catch(Exception e)
{
Log.d("TAG_NAME", e.getMessage() );
}
}
}
// billsModel=new Bills_model();
resultSet.put(rowObject);
Log.d("resultset",resultSet.toString());
}
while (c.moveToNext());
}
} catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
//出認沽即將到來這樣
[{「key」,「value」},{「key」,「value」} ....]
//但我想這樣可能
{ 「產品」[{ 「鍵」, 「值」},{ 「關鍵」, 「價值」} ....]}
,我現在有另一個問題,首先我想從sqlite數據庫中獲取數據,我想轉換; – gautam
[{「bill_date」:「30-09-2016」,「bill_list」:[{「id」:「144」,「invoice_no」:「INV11255」}]},] – gautam