【发布时间】:2018-05-11 10:20:08
【问题描述】:
从我的 Json 的内部 ArrayList 和变量中取出数据时遇到问题。我可以将我的 Json 读入字符串并打印出来,但是当我调用 fromJson 并访问生成的类时,我的数组列表为空,所有数据均为空白。
下面的示例代码。
我的 Json 字符串打印:
{
'ShippingList': {
'ShippingInfo': {
'ShipList_No': 'SP10000001',
'Ship_Date': 'Nov-14-2017'
},
'ItemInfo': [{
'Item_SerialNumber': 'item0000001',
'Bin_Location': '3',
'QTY': '1'
},
{
'Item_SerialNumber': 'item0000002',
'Bin_Location': '3',
'QTY': '1'
},
{
'Item_SerialNumber': 'item0000003',
'Bin_Location': '3',
'QTY': '1'
},
{
'Item_SerialNumber': 'item0000004',
'Bin_Location': '3',
'QTY': '1'
},
{
'Item_SerialNumber': 'item0000005',
'Bin_Location': '3',
'QTY': '1'
}
]
}
}
Gson 代码:
Gson Gos = new Gson();
ShipList SL = Gos.fromJson(inList,ShipList.class);
String temtem = SL.getALI().get(0).getSerial();
Log.d("Proof! ","wadda " + temtem);
这只会打印:证明!瓦达
我的课程适合 Json 的内容,并且已经被序列化。我已经成功地创建了一个类并将其转换为 Json,但我无法正确地从 Json 转换为对象
【问题讨论】:
-
上述 json 包含错误,这就是 GSON 不解析它的原因