将大型 ArrayList 存储到 SQLite
我正在开发一个应用程序,在其中不断下载大量数据。
json格式的数据,我使用Gson对其进行反序列化。现在我将其存储在 SQLite 数据库中。我必须计算关系并将它们存储到关系数据库中。然而这需要太多时间。
将类对象保存到数据库会方便得多。
反序列化后的数据看起来像这样:
Class A{
private String name;
private List<B> subItems;
}
Class B{
private String name;
private List<C> subItems
}
我可以用更简单的方式持久化它,例如使它们可序列化吗?这怎么能做到呢?
I im developing a application in which I continuously download large amount of data.
The data in json format and I use Gson to deserialize it. By now Im storing this in a SQLite db. And I have to calculate the relationship and store them into a relationship db. However this takes too much time.
It would be much more convenient to save the class objects to db.
The data looks something like this after deserialization:
Class A{
private String name;
private List<B> subItems;
}
Class B{
private String name;
private List<C> subItems
}
Can I persist this in a easier way, for example by making them serializable? How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,序列化对于您的情况来说是一个更好的解决方案,并且它适用于 Android。以下示例取自 http://www.jondev.net/articles/Android_Serialization_Example_%28Java%29
序列化方法:
反序列化方法:
Yes, serialization is a better solution in your case and it works in Android. The following example is taken from http://www.jondev.net/articles/Android_Serialization_Example_%28Java%29
serialization method:
deserialization method: