can I save big JSON object directly to sqlite databse

时间:2015-11-12 10:46:13

标签: android json database string sqlite

how can I save JSON object into sqlite database. Which is the best data type to save JSON object in sqlite? Now I am using String data type to save JSON data.

2 个答案:

答案 0 :(得分:2)

Just save it in the TEXT/VARCHAR format. JSON is nothing but textual representation of Data.

Write to DB

String data = jsonObject.toString();
//save data to db

Read from DB

String data = //read from db
JSONObject jsonObject = new JSONObject(data);

答案 1 :(得分:0)

There is no specific type for JSONObject.

All you can do is make String from your JSONObject and write it to database using:

String myString = myJsonObject.toString();
//make DB insert here

Then when needed, just read it:

String myString = /* read from DB here */
JSONObject myjsonObject = new JSONObject(myString);

Type for column should be TEXT - SQLite doc