I have a table with several records in SQLite
, and also other data in SharedPreferences
.
I would like to generate a JSON
by pulling those records, and together that SharedPreferences
data.
But in search, I barely found examples using only standard Android and Java (not GSON, etc.) classes as JSONObject
and JSONArray
.
For example:
SharedPreferences - 1 registro
Chave: usuario
Chave: token
SQLite - vários registros
Tabela: registros
Campos: id, usuario, anotacao
I wanted a JSON basically this way:
{
"shared": [{
"usuario": "fulano"
},
{
"token": "xyz123"
}
],
"regs": [{
"id": "10",
"usuario": "1",
"anotacao": "teste"
}, {
"id": "11",
"usuario": "2",
"anotacao": "teste 2"
}]
}
I think I should connect to SQLite, create a cursor, cycle through the records and fields by adding each value, and then I can manually do one for SharedPreferences.
But the problem is this, I do not find examples! If you have links thank you.