I'm receiving that string from java code:
{devices:[3962], contacts:[{_userId='1', _contactId='(+1)1111111', _contactName='Name Surname'}]} and I want to convert it into normal object, but it's not a valid JSON format. Do you have any ideas?
Or maybe somebody can help me with JAVA code. I suppose that all the magic goes here:
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public String extractDbDump() {
return "{devices:" + getDevices() + ", contacts:" + getContacts() + "}";
}
private String getContacts() {
List<ContactItem> contactList = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_CONTACT;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
ContactItem contact = new ContactItem();
contact.userId = cursor.getString(0);
contact.contactName = cursor.getString(1);
contact.contactId = cursor.getString(2);
contactList.add(contact);
} while (cursor.moveToNext());
}
db.close();
return "" + contactList.toString();
}
private String getDevices() {
List<String> deviceList = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_DEVICE;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor != null && cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
deviceList.add(cursor.getString(0));
} while (cursor.moveToNext());
}
}
db.close();
return deviceList.toString();
}
public class ContactItem {
public String userId;
public String contactId;
public String contactName;
@Override
public String toString() {
return "{" +
"_userId='" + userId + '\'' +
", _contactId='" + contactId + '\'' +
", _contactName='" + contactName + '\'' +
'}';
}
}