0

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.

PrincessLeiha
  • 3,144
  • 4
  • 32
  • 53
  • 2
    Try [this](http://sites.google.com/site/gson/gson-user-guide#TOC-Custom-Serialization-and-Deserializ), [this](http://stackoverflow.com/questions/4556230/using-gson-in-android-to-parse-a-complex-json-object) and [this](http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html). – Ghost Mar 02 '12 at 06:59

1 Answers1

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

This worked for me....

PrincessLeiha
  • 3,144
  • 4
  • 32
  • 53