【问题标题】:Gson Serialization in androidandroid中的Gson序列化
【发布时间】:2012-03-02 06:23:16
【问题描述】:

我的数据库中有一些数据,我想将这些数据放入序列化的 JSON 格式中。我如何使用 GSON 序列化来做到这一点?

可用的示例没有显示如何获取数据然后以格式插入。

【问题讨论】:

标签: android gson


【解决方案1】:

回答

Gson manJson = new Gson(); 
ArrayList<MyTableName> list=new ArrayList<MyTableName>();
for(int i=0;i<count;i++){
    cursor2.moveToNext();
    MyTableName data=new MyTableName();
        data.setMyVal(cursor2.getString(cursor2.getColumnIndex("MyVal")));
        list.add(data);
}
String jsonData=manJson.toJson(list);

这对我有用....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多