相关疑难解决方法(0)

如何在SQLite数据库中存储JSON对象

如何在SQLite数据库中存储JSON对象?什么是正确的方法?

一个地方是blob类型列.如果我可以将JSON对象转换为字节数组并使用Fileoutputstream

另一个想法是将文本列存储为String

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

database sqlite android json

55
推荐指数
3
解决办法
10万
查看次数

标签 统计

android ×1

database ×1

json ×1

sqlite ×1