【发布时间】:2022-01-01 01:18:52
【问题描述】:
我有一种来自服务的数据
- 服务 A 返回:
{
"name": "foo",
"id": 333,
"contact": [
{
"type": "phone",
"number": "12333333"
},
{
"type": "phone",
"number": "22333333"
}
]
}
- 我为它准备了一个模型类:
public class People {
public String name;
public int id;
public List<Contact> contact;
public static class Contact {
public String type;
public String number;
}
}
- 但服务 B 返回:
{
"name": "foo",
"id": 333,
"contact":{
"entries": [
{
"type": "phone",
"number": "12333333"
},
{
"type": "phone",
"number": "22333333"
}
]
}
}
真实情况是json中有10个list,这个json中的所有list都被一个对象包裹,那么“entries”就是实际的list。 我已经在其他地方使用了模态类,我只想将它们视为同一个类,例如:
Contact contact = people.contact
有什么想法吗?
【问题讨论】: