我的Json响应如下所示,并且混淆了如何使用GSON解析它。 请查看以下内容并指导我如何使用GSON解析它。
{
"GetMICSDataResult": {
"CONVERTIONFACT": [
{
"CONVERSIONFACT": "1",
"ITEMNO": "S1300W",
"UOM": "Ea."
},
{
"CONVERSIONFACT": "1",
"ITEMNO": "S1300Y",
"UOM": "Ea."
}
],
ITEMDETAILS": [
{
"ITEMDESC": "FluorescentDeskLamp",
"ITEMNO": "A11030",
"LOCATION": "1",
"PRICELIST": "WHS",
"QTYONHAND": 164,
"UNITPRICE": 38.3,
"UOM": "Ea."
},
{
"ITEMDESC": "FluorescentDeskLamp",
"ITEMNO": "A11030",
"LOCATION": "2",
"PRICELIST": "WHS",
"QTYONHAND": 247,
"UNITPRICE": 38.3,
"UOM": "Ea."
}
]
} }
答案 0 :(得分:2)
Gson gson = new Gson();
YourClass class = gson.fromJson(jsonInString, YourClass.class);
答案 1 :(得分:1)
有很简单的方法可以做到这一点。只需使用POJO生成器http://www.jsonschema2pojo.org/,它将为您提供带有必要注释的普通对象。您也可以使用Json格式化程序来验证您的json https://jsonformatter.curiousconcept.com/ - 您发布的JSON无效。