0
安裝程序會自動JSON詞典: - Android電子 - 改造2 - GSON如何映射與GSON
我的服務器JSON看起來是這樣的:
{
"myList1":
{
"1": (<- variable number)
{
"id":"1","name":"user123"
},
"2"{},...},
"myList2":
{
"299": (<- variable number)
{
"id":"20","name":"user42"
},
"300":
{},...}
}
的第一個節點: 「myList1」 和「 myList2「已修復。
然後,第二節點包含可變數目的
和第二節點holdes一個用戶對象。
- >如何使用gson定義第二個列表的響應?
- >的數量和項目的數量是可變的
我的迴應的映射是這樣的:
public class ResponeDef {
@Gson.Named("myList1")
ResponeListDef list1;
@Gson.Named("myList2")
ResponeListDef list1;
}
public class ResponeListDef {
@Gson.Named("??")
ResponeListEntryDef entry1
@Gson.Named("??")
ResponeListEntryDef entry2;
}
public class ResponeListEntryDef {
@Gson.Named("id")
int id;
@Gson.Named("name")
String userName;
}
這可能會幫助註冊GSON類型的適配器:HTTPS ://stackoverflow.com/questions/16891243/parse-json-with-variable-key –