Reputation: 3174
I have some data in my DB and i want to put that data in serialized JSON format. How do I do that using GSON serialization?
The examples available do not show how to get the data and then insert it in the format.
Upvotes: 0
Views: 1180
Reputation: 3174
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);
This worked for me....
Upvotes: 1