java - 我应该如何将此 JSON 转换为 POJO 类?
问题描述
这是我的 JSON 回复
{
"value":{
"Status":1
"Affected segments":[]
"Message":[]
}
}
但这就是未来可能的样子
{
"value":{
"Status":2
"Affected segments":[{a},{b},{c}]
"Message":[
{
"Content": "suhrfuahfuhasufhalushflashlfuhasurhaus",
"Created date": "12/2/21"
},{
"Content": "suhrfuahfuhasufhalushflashlfuhasurhaus",
"Created date": "15/2/21"
},
]
}
}
正如您在第一个代码片段中看到的那样,“状态”为 1 表示没有异常,而在第二个代码片段中,“状态”为 2 表示更改,因此数组已填充。
我将如何解析他们两个?
解决方案
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.
class Message {
String content;
LocalDate date;
}
推荐阅读
- dart - 什么时候在 Dart 中使用 num
- r - 我有 3 个分类,但我的决策树只显示 2 个
- caching - 如何强制加载当前版本的离线网络应用程序?
- asp.net - 仅在文本框中对数字和“,”字符使用 RegularExpressionValidator
- excel - 在漏斗图中更改轴标签字体大小 (Excel 2016)
- excel - 为什么单元格不恢复为 ActiveCell.FormulaR1C1?
- r - 多个数据框到多个 html 表,但都一个接一个地显示
- javascript - 泄漏的原因是什么?
- java - Elasticsearch - 在查询中将数组作为参数传递
- ios - 更新后结构崩溃:[Fabric isCrashlyticsCollectionEnabled]:无法识别的选择器发送到类 0x10c0bb918