需要将 json 响应转换为 java pojo,其中字段(在示例中为 'performers' )可以返回为 {} 或 [{},{}] 或 null,如下例所示:
示例1:performer value here is a list of datas '{}'.
{
title:"Sample title1",
performers: {
performer:[{
creator: "AAAA",
linker: "XXX",
},
{
creator: "BBBBB",
linker: "YYY",
}]
},
venue_address: "sample addr1"
}
示例 2:performer value here is just data '{}'
{
title:"sample title2",
performers: {
performer: {
creator: "AAAA",
linker: "YYY",
}
},
venue_address: "sample addr2"
}
示例 3:performer value is null here
{
title:"sample title3",
performers:null,
venue_address: "sample addr3"
}
我们如何在gson.fromJson
.As的帮助下将此 json 响应转换为 java pojo"Expecting an OBJECT but found is ARRAY"