【发布时间】:2017-05-08 09:12:16
【问题描述】:
我尽量解释我的情况。我想用 Gson 读取一个包含对象列表的 JSON 文件。这个对象是基类,因为我有几个扩展它的对象。
{
"name":"Test",
"url":"http://test.test",
"script":[
{ "actionId":1, "actionType":"click", "id":"testId", "redirect" : "http://google.de" },
{ "actionId":2, "actionType":"write", "id":"testId2", "content":"testContent" }
]
}
基类称为ScriptElement,它也包含每个子对象所需的一些值。 ScriptInput 和 ScriptClickable 是孩子。
如果我将列表转换为 JSON,我会得到一个生成良好的 JSON 文件。但是当我读取JSON文件并将其转换回对象时,它只包含ScriptElement对象,并且缺少ScriptInput和ScriptClickable的附加信息。
【问题讨论】:
-
你至少可以给我们看 json 文件!
-
{ "name":"Test", "url":"http://test.test", "script":[ { "actionId":1, "actionType":"click", "id":"testId", "redirect" : "http://google.de" }, { "actionId":2, "actionType":"write", "id":"testId2", "content":"testContent" } ] }我试图将它添加到正文中,但我永久收到代码无效的消息。不知道为什么。 -
你可以编辑你的帖子而不是你的评论吗?
-
就像我说的,我不能。系统提示我的代码有错误,无法添加。