[英]How should I convert this JSON to a POJO class?
This is my JSON reply这是我的 JSON 回复
{
"value":{
"Status":1
"Affected segments":[]
"Message":[]
}
}
But this is what it can be in the future但这就是未来可能的样子
{
"value":{
"Status":2
"Affected segments":[{a},{b},{c}]
"Message":[
{
"Content": "suhrfuahfuhasufhalushflashlfuhasurhaus",
"Created date": "12/2/21"
},{
"Content": "suhrfuahfuhasufhalushflashlfuhasurhaus",
"Created date": "15/2/21"
},
]
}
}
as you can see in the 1st snippet of code the "status" is 1 to indicate nothing out of the ordinary whereas in the 2nd code snippet the "status" is 2 to indicate a change hence the array is filled.正如您在第一个代码片段中看到的那样, “状态”为 1 表示没有任何异常,而在第二个代码片段中, “状态”为 2 表示更改,因此数组已被填充。
How would I parse the two of them??我将如何解析他们两个?
Could you just create simply entity Message which would store the 'Content' and the 'Date'?您能否只创建简单的实体消息来存储“内容”和“日期”? Then you could store the messages in
List<Message>
and check whether this is empty or not, to validate the condition you have.然后您可以将消息存储在
List<Message>
并检查它是否为空,以验证您的条件。
class Message {
String content;
LocalDate date;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.