既然你的避风港没有公布源代码到ToggleProcessedImage
(或者它本身可能包含的任何对象),我无法告诉你为什么你的JSON不是反序列化。 Gson需要一个特定字段的数组,但JSON似乎包含该字段的一个对象。
我看着你的JSON列1258(其中错误发生),并认为它是:
"MeasuredBox": {
...
}
现在早,你也有:
"MeasuredBoxes": [
...
]
是否有可能在其中一个类别,您意外地将measuredBox
字段的类型定义为List<MeasuredBox>
或MeasuredBox[]
而不是仅仅是MeasuredBox
?也许你把它与名称相似的字段measuredBoxes
混淆了。
编辑
在回答您的评论。您发布的MeasuredBoxes
是:
public class MeasuredBoxes {
public Box Region;
public List<Integer> LayerBottoms;
public List<Measurement> Measurements;
public List<Box> MeasuredBox; //<--- this is the source of your error
...
}
这就是您的错误。类MeasuredBoxes
需要属性的Box
对象列表。但是,您提供的JSON只有一个Box
,它直接表示为一个对象。
为了解决这个问题,您可能需要改变你的JSON这样MeasuredBox
是一个数组:
"MeasuredBox": [{
...
}]
或更改MeasuredBoxes
类使得MeasuredBox
场Box
型的,而不是List<Box>
:
public class MeasuredBoxes {
public Box Region;
public List<Integer> LayerBottoms;
public List<Measurement> Measurements;
public Box MeasuredBox; //<--- this is Box now instead of List<Box>
...
}
另一方面,请使用Java命名约定。变量(这包括班级字段)和方法应该是namedLikeThis
(即骆驼式)和NotLikeThis
,但是班级应该是NamedLikeThis
。
最好保留班级成员private
;使他们public
是例外,而不是规则。
您是否检查过JSON以查看它是否有效? 'l_sParamProcessedImage'包含什么?它与“ToggleProcessedImage”的结构相匹配吗?请发布您试图反序列化的JSON,以及'ToggleProcessedImage'的源代码。 –
是的,我发布了l_sParamProcessedImage的值。是的,它匹配toogleProcessedImage的来源 – PSDebugger
不是我不相信你,但它有助于有更多的目光:) - 你可以发布'ToggleProcessedImage'的来源吗? –