public class myClass {
private String myVar1;
private String myVar2;
}
List<myClass> list = generateListWithGson();
System.out.println(list.toString());
// returns
[
myClass(myVar1=OneDummyString, myVar2=TwoDummyString),
myClass(myVar1=OneDummyString, myVar2=TwoDummyString),
...
]
我渴望像這樣格式化:如何把List <Class>轉換成Array?
// desired output:
[
{
"myVar1" : "OneDummyString",
"myVar2" : "TwoDummyString",
},
{
"myVar1" : "OneDummyString",
"myVar2" : "TwoDummyString",
},
...
]
爲什麼你需要重新發明輪子揚鞭? –
:D @JoeC只需要將這些數據格式化即可。 –
看起來您正在尋找列表的json表示形式。試試傑克遜或圖書館。示例 - http://www.studytrails.com/java/json/java-jackson-serialization-list/ –