我从外部API收到以下格式的json响应。但是我不确定如何将其转换为POJO以便稍后在应用程序中分别获取所有这些值
{
"count": 1,
"item_list": [
{
"property_value_map": {
"Data": {
"content_type": "image/jpeg",
"data": "ZJRgABAAEASABIAAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS"
},
"DataType": 0,
"LastChanged": "2015-12-11T17:21:15+00:00",
"ObjectType": 1,
"PersonID": 1384
}
}
],
"page_number": 1,
"page_size": 20,
"total_items": 1,
"total_pages": 1,
"type_name": "Lnl_MultimediaObject",
"version": "1.0"
}
我如下创建了一个POJO并将其转换为JSON。但是问题是我不知道如何从JSON上方获取“数据”的值,因为我的item_list是对象
public class GetInstancesResponseVO {
private int count;
private List<Object> item_list;
private int page_number;
private int page_size;
private int total_items;
private int total_pages;
private String type_name;
private String version;
public GetInstancesResponseVO() {}
/***Getters Setters **/
}
更新
按照JaumeMoróni Tarrasa的建议进行一次pojo尝试
public class GetInstancesResponseVO {
private int count;
private List<PropertyValueMap> item_list;
private int page_number;
private int page_size;
private int total_items;
private int total_pages;
private String type_name;
private String version;
/***CONSTRUCTOR, SETTERS, GETTERS***/
}
但是我得到null。这是我的PropertyValueMap POJO;
public class PropertyValueMap {
private MyData Data;
private int DataType;
private String LastChanged;
private String ObjectType;
private String PersonID;
public PropertyValueMap() {}
/***GETTERS,SETTERS**/
}
还有数据POJO;
public class MyData implements Serializable{
private String content_type;
private String data;
public MyData() {}
/***GETTERS, SETTERS**/
}
我在PropertValueMap POJO中尝试了将数据作为字符串使用,无论哪种方式,我都会得到null;
{
"count": 1,
"item_list": [
{
"objectType": null,
"data": null,
"personID": null,
"lastChanged": null,
"dataType": 0
}
],
"page_number": 1,
"page_size": 20,
"total_items": 1,
"total_pages": 1,
"type_name": "Lnl_MultimediaObject",
"property_value_map": null,
"version": "1.0"
}
而且JSON响应看起来也不正确,因为它缺少“ property_value_map”。非常感谢您的帮助,因为我要为此再浪费一天。