2012-03-02 15 views
0

私のDBにはいくつかのデータがあり、そのデータをシリアル化されたJSON形式で入れたいと思っています。 GSONシリアライゼーションを使って、どうすればいいですか?androidでのGsonのシリアル化

使用可能な例では、データを取得してフォーマットに挿入する方法が示されていません。これは私のために働いた

+2

(http://sites.google.com/site/gson/gson-user- [この]を試してみてくださいガイド#TOC-Custom-Serialization-and-Deserializ)、[this](http://stackoverflow.com/questions/4556230/using-gson-in-android-to-parse-a-complex-json-object)および[this](http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html)。 – Ghost

答えて

1

ANSWER

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); 

....

関連する問題