保存在SQLite数据库的ArrayList存在、数据库、SQLite、ArrayList

由网友(我与途人i.)分享简介:所以,我要救double值的有序集合,我希望能够插入,检索或轻松地删除这个任意值。作为这样的,我使用的是一个ArrayList,在那里我定义了一类称为双打存储的双重价值。So I want to save an ordered set of double values, and I want to be able t...

所以,我要救double值的有序集合,我希望能够插入,检索或轻松地删除这个任意值。作为这样的,我使用的是一个ArrayList,在那里我定义了一类称为双打存储的双重价值。

So I want to save an ordered set of double values, and I want to be able to insert, retrieve or delete any value from this easily. As of such, I'm using a an ArrayList, where I define a class called Doubles to store the double values.

我如何保存此ArrayList中的一个记录在SQLite数据库?我的意思是...我应该列类型?能不能做到?

How do I store this arraylist in a record in an SQLite database? I mean...what should the columns type be? Can it be done?

感谢。

推荐答案

您不能插入ArrayList中直接进入sqlite的。相反,你可以使用的JSONObject(org.json.JSONObject)插入ArrayList中。请检查下面的代码片段,您可以尝试像下面......

You cannot insert ArrayList directly into Sqlite. Instead, you could use JSONObject (org.json.JSONObject) to insert the ArrayList. Please check below snippet, you can try something like below....

要插入,

JSONObject json = new JSONObject();
json.put("uniqueArrays", new JSONArray(items));
String arrayList = json.toString();

将字符串到数据库。

Insert the string into db.

要读,          阅读从数据库字符串作为字符串,

To Read, Read the string from db as String,

 JSONObject json = new JSONObject(stringreadfromsqlite);
  ArrayList items = json.optJSONArray("uniqueArrays");
阅读全文

相关推荐

最新文章