如何在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)