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 –