Gson的代码
mJsonDataFromAssets = JAssetsUtils.getJsonDataFromAssets(this, "chineseCountryJson.json"); Gson gson = new Gson(); List<ContryCodeBean> contryList = gson.fromJson(mJsonDataFromAssets, new TypeToken<List<ContryCodeBean>>() {}.getType());
json数据
{
"data": [
{
"countryName": "安道尔",
"countryPinyin": "andao er",
"phoneCode":"376",
"countryCode":"AD"
},
{
"countryName": "阿拉伯联合酋长国",
"countryPinyin": "ala bo lian he qiu zhang guo",
"phoneCode":"971",
"countryCode":"AE"
}
]
}
public class ContryCodeBean implements Serializable { private List<DataBean> data; public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } @Setter @Getter public static class DataBean implements Serializable{ /** * countryName : 安道尔 * countryPinyin : an dao er * phoneCode : 376 * countryCode : AD */ private String country_name; private String country_pinyin; private String phone_code; private String country_code; } }
解决办法
把json数据改成了
[ { "data": [ { "countryName": "安道尔", "countryPinyin": "an dao er", "phoneCode": "376", "countryCode": "AD" }, { "countryName": "阿拉伯联合酋长国", "countryPinyin": "a la bo lian he qiu zhang guo", "phoneCode": "971", "countryCode": "AE" }]
}]解决问题