新浪微博获取用户微博的接口说明 链接描述
根据接口,返回的是复杂的json数据,我截取了获取到的数据中的一段,尝试用gson进行解析,结果发现解析报错。下边是截取的部分json文件的内容,请教大家:
user这个key对应的java类型应该是什么呢?我试了List和ArryList都不对,不知道他对应的类型是什么
{
"statuses": [
{
"created_at": "Fri Dec 02 17:05:40 +0800 2016",
"id": 4048283825629844,
"mid": "4048283825629844",
"idstr": "4048283825629844",
"text": "前卫 //@主治医湿:造型有点害怕 //@冷知君:原谅我不懂时尚 //@城南邮局:最后是刘梓晨吧 //@话提:走远了……",
"user": {
"id": 5680719858,
"idstr": "5680719858",
"class": 1,
"screen_name": "综艺博主",
"name": "综艺博主",
4 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
没用过这个库,不过看错误信息,问题应该在这句:
jsonstring abc = gson.fromJson(jsonfile,jsonstring.class);
提示java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY。
你确定gson.fromJson(jsonfile,jsonstring.class)返回的类型是jsonstring吗?
12345678_0001
TA贡献1802条经验 获得超5个赞
很明显啊,就是一个普通的对象。
而且根据json创建对应的类,应该用插件,直接避免了你这种问题。
private UserBean user;
public static class UserBean {
private int id;
private String screen_name;
private String name;
private String province;
private String city;
private String location;
private String description;
private String url;
private String profile_image_url;
private String domain;
private String gender;
private int followers_count;
private int friends_count;
private int statuses_count;
private int favourites_count;
private String created_at;
private boolean following;
private boolean allow_all_act_msg;
private String remark;
private boolean geo_enabled;
private boolean verified;
private boolean allow_all_comment;
private String avatar_large;
private String verified_reason;
private boolean follow_me;
private int online_status;
private int bi_followers_count;
添加回答
举报
0/150
提交
取消