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



Gson的代码
mJsonDataFromAssets = JAssetsUtils.getJsonDataFromAssets(this, "chineseCountryJson.json");
Gson gson = new Gson();
List contryList = gson.fromJson(mJsonDataFromAssets, new TypeToken>() {

}.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 data;

    public List getData() {
        return data;
    }

    public void setData(List 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"
        }
		]
     }
]
解决问题

你可能感兴趣的:(bug)