我的Json数组看起来像这样
[
{
"geoRegion":"101",
"companyName":"101",
"department":"101",
"industry":"101",
"sector":"101",
"formName":"101",
"formType":true,
"fields":[
{
"labelId":"102",
"bizJust":"101"
},
{
"labelId":"103",
"bizJust":"101"
},
{
"labelId":"104",
"bizJust":"101"
},
{
"labelId":"129",
"bizJust":"102"
},
{
"labelId":"128",
"bizJust":"102"
},
{
"labelId":"144",
"bizJust":"102"
},
{
"labelId":"143",
"bizJust":"102"
}
]
}
]
我的代码如下:
public Map<String,String> createTransaction(String lang) throws Exception {
Gson gson =new Gson();
JsonObject jsonObj=gson.fromJson(lang, JsonObject.class);//Exception thrown at this line
}
答案 0 :(得分:2)
尝试将所有内容放入JSON数组而不是JSON对象。
从
更改您的代码JsonObject jsonObj=gson.fromJson(lang, JsonObject.class);
为:
JsonArray array = gson.fromJson(lang, JsonArray.class);