I want to convert arraylist to json object. I did find everything in stackoverflow but could not get my answer. Here is the format which i want.
$str = '{
"0": {
"product_name 2": "Johnson Baby (Soap)",
"product_total 1": "288"",
"product_quantity": "3"
},
"1": {
"product_name 2": "Johnson Baby (Soap)",
"product_total 1": "288"",
"product_quantity": "3"
}
}';
But i am unable to achieve this what i am getting is like this.
{
"product_qtn": {
"Quantity 2": "4",
"Quantity 1": "3",
},
"product_total": {
"Price1": "288",
"Price2": "112",
},
"product_name": {
"Name3": "Johnson Baby (Soap)",
"Name2": "Johnson baby (powder)",
}
}
I am getting data from sqlite and storing in arraylist here is the code.
dataBase = mHelper.getWritableDatabase();
mCursor = dataBase.rawQuery("SELECT * FROM "
+ DBHelper.TABLE_NAME + " WHERE " + DBHelper.KEY_COUNT
+ " IS NOT NULL AND " + DBHelper.KEY_COUNT + " != '0'", null);
product_price.clear();
productprice = 0;
if (mCursor.moveToFirst()) {
do {
product_price.add(mCursor.getString(mCursor
.getColumnIndex(DBHelper.KEY_PRODUCT_TOTAL_PRICE)));
product_name.add(mCursor.getString(mCursor
.getColumnIndex(DBHelper.KEY_PNAME)));
product_quantity.add(mCursor.getString(mCursor
.getColumnIndex(DBHelper.KEY_COUNT)));
} while (mCursor.moveToNext());
}