i want to make sqlite data to jsonarray but i get some problem i have write this code to parse from sqlite to arraylist with hasmap and change it to json with it use gson to convert
public ArrayList<HashMap<String, String>> tampil_meja() {
SQLiteDatabase database = this.getWritableDatabase();
ArrayList<HashMap<String, String>> arrayListMeja = new ArrayList<HashMap<String, String>>();
Cursor cursor = database.rawQuery("SELECT * FROM "+ TABLE_MEJA , null);
if (cursor.moveToFirst()) {
do {
HashMap<String, String> hashMapBiodata = new HashMap<String, String>();
hashMapBiodata.put("id", cursor.getString(0));
arrayListMeja.add(hashMapBiodata);
} while (cursor.moveToNext());
}
cursor.close();
return arrayListMeja;
}
and this is how to parse it
ArrayList<HashMap<String, String>> arrayListPesan = sqLiteHelper.tampil_semua_pesanan();
userFunction.gson(arrayListPesan);
Gson gson = new Gson();
String jsonPesan = gson.toJson(arrayListPesan);
but i get it is like this
[{"id":"11","jjumlah":"12","nama":"Ayam Goreng"},{"id":"11","jjumlah":"12","nama":"Ayam Goreng"},{"id":"11","jjumlah":"12","nama":"Ayam Goreng"}]
i want to be like this
["makanan":{"id":"11","jumlah":"12","nama":"Ayam Goreng"},{"id":"11","jumlah":"12","nama":"Ayam Goreng"},{"id":"11","jumlah":"12","nama":"Ayam Goreng"}]
can anyone help me
Aucun commentaire:
Enregistrer un commentaire