保存在SQLite数据库的ArrayList [英] Saving ArrayLists in SQLite databases

查看:744
本文介绍了保存在SQLite数据库的ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我要救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");

这篇关于保存在SQLite数据库的ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆