如何在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();
    }
}
回答:
将JSONObject转换为String并另存为TEXT / VARCHAR。 在检索同一列时,将String转换为JSONObject。
例如
String stringToBeInserted = jsonObject.toString();//and insert this string into DB
String json = Read_column_value_logic_hereJSONObject jsonObject = new JSONObject(json);
以上是 如何在SQLite数据库中存储JSON对象 的全部内容, 来源链接: utcz.com/qa/432861.html
