将ArrayLists保存在SQLite数据库中 [英] Saving ArrayLists in SQLite databases

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

问题描述

所以我想保存一组有序的double值,我想能够轻松地插入,检索或删除任何值。这样,我使用一个ArrayList,在那里我定义一个名为Doubles的类来存储双精度值。

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.

如何将此数组列表存储在记录中一个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();

将字符串插入db。

阅读,
从db中读取字符串作为String,

To Read, Read the string from db as String,

 JSONObject json = new JSONObject(stringreadfromsqlite);
  ArrayList items = json.optJSONArray("uniqueArrays");

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

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