如何在 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();
}
}
将 JSONObject 转换为 String 并保存为 TEXT/ VARCHAR。在检索同一列时,将 String 转换为 JSONObject。
例如
写入数据库
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)