【发布时间】:2015-03-23 07:47:25
【问题描述】:
我有两个具有相似字段的 JSON 对象。唯一的区别是第一个总是有字段
type: "type1"
并且 second 可以在 'type' 字段中包含除 'type1' 之外的任何内容。
我希望将它们解析为具有不同类的 java 对象(使用类 FirstType.class 和 OtherType.class)。有可能吗?
对象一:
{
id: "1j23jr8swgs8"
type: "type1"
}
对象二:
{
id: "3sdaa3dq18"
type: "unknown_type"
}
还有java类:
class FirstType
{
String id;
}
class OtherType
{
String id;
}
【问题讨论】:
-
你能发布完整的 json 吗?
-
我们需要更多解释来帮助您。
-
当然可以,但具体代码取决于你的json结构。
标签: java android json gson retrofit