如何在SQLite数据库中存储JSON对象?什么是正确的方法?如何在SQLite数据库中存储JSON对象
一个地方是blob类型列。如果我能在JSON对象转换成字节数组,并使用FileOutputStream中
另一个想法是在文本列来存储作为一个字符串
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();
}
}
2013-05-17
Kevik
+3
[JSON是*数据的文本表示](http://json.org)。因此将它保存在TEXT列/类型关联中。将它编码为BLOB只会使更多的工作/痛苦 - 不要这样做!当然,*从'JSONObject'(它不是* JSON)获取实际的JSON *。这可以通过['jsonObject.toString()'](http://www.json.org/javadoc/org/json/JSONObject.html#toString())完成。 –
+0
如果Sqlite不是强制使用,那么我的建议是,写File.txt文件并将整个响应保存在文件中,并在需要时读取它 –