java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

来源:互联网 发布:mysql修复表命令 编辑:程序博客网 时间:2024/05/25 18:12
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"        }
]
     }
]
解决问题

阅读全文
0 0
原创粉丝点击