在我的应用程序上添加备份功能,并且我正在使用realm数据库,我想将其备份到json文件。我已经创建了用于读取数据库和创建jsonobject的函数。在执行jsonobject.tostring时,我遇到了一个outofmemory错误,因为我有20多万条记录。创建json文件的任何其他方法。
RealmResults<StoneModelR> allStones = realm.where(StoneModelR.class).sort("id", Sort.ASCENDING).findAll();
for (StoneModelR singleStone : allStones) {
try {
JSONObject jObjectStone = new JSONObject();
jObjectStone.put("stoneid", singleStone.id);
jObjectStone.put("lat", singleStone.lat);
jObjectStone.put("lng", singleStone.lon);
jObjectStone.put("userid", singleStone.userid);
jObjectStone.put("owner", singleStone.owner);
jObjectStone.put("timestamp", singleStone.timestamp);
jObjectStone.put("stonetype", singleStone.stonetype);
jObjectStone.put("remarks", singleStone.description);
jObjectStone.put("imported", singleStone.imported);
jArrayStones.put(jObjectStone);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
JSONObject stoneObj = new JSONObject();
try {
stoneObj.put("stones", jArrayStones);
} catch (JSONException e) {
e.printStackTrace();
}
暂无答案!
目前还没有任何答案,快来回答吧!