Wie speichere ich ein JSON-Objekt in einer SQLite-Datenbank? Was ist der richtige Weg?So speichern Sie ein JSON-Objekt in der SQLite-Datenbank
ein Platz ist die Blob-Typ-Spalte. wenn ich das JSON-Objekt in Byte-Array umwandeln und verwenden Fileoutputstream
die andere Idee ist, in einer Textspalte als String speichern
import org.json.JSONObject;
JSONObject jsonObject;
public void createJSONObject(Fields fields) {
jsonObject = new JSONObject();
try {
jsonObject.put("storedValue1", fields.storedValue1);
jsonObject.put("storedValue2", fields.storedValue2);
jsonObject.put("storedValue3", fields.storedValue3);
jsonObject.put("storedValue4", fields.storedValue4);
jsonObject.put("storedValue5", fields.storedValue5);
jsonObject.put("storedValue6", fields.storedValue6);
} catch (JSONException e) {
e.printStackTrace();
}
}
[JSON ist * eine textuelle Darstellung von Daten *] (http://json.org). Speichern Sie es in einer TEXT-Spalte/Typ-Affinität. Es als BLOB zu kodieren macht einfach mehr Arbeit/Schmerz - tu das nicht! Natürlich, * holen Sie sich den tatsächlichen JSON * aus dem 'JSONObject' (was * nicht * JSON ist). Das kann mit ['jsonObject.toString()'] (http://www.json.org/javadoc/org/json/JSONObject.html#toString()) gemacht werden. – user2246674
Wenn Sqlite nicht obligatorisch ist, dann mein Vorschlag ist, dass Datei.txt Datei schreiben und ganze Antwort in Datei speichern und lesen, wenn Sie brauchen –