标签:
1.gson可以把json映射到实体类,也可以映射到map中(不一定是hashmap),例如:
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
或
Gson gson = new Gson();
String json 如下;
{ "ret":0, "msg":"", "nickname":"xxx", "figureurl":"http://qzapp.qlogo.cn/qzapp/100226195/C399C7B2880641627CED3EEF9DEB8E30/30", "figureurl_1":"http://qzapp.qlogo.cn/qzapp/100226195/C399C7B2880641627CED3EEF9DEB8E30/50", "figureurl_2":"http://qzapp.qlogo.cn/qzapp/100226195/C399C7B2880641627CED3EEF9DEB8E30/100", "gender":"xxx", "vip":"0", "level":"0", "is_yellow_year_vip":"0" }
Map infoMap = gson.fromJson(json,
2.记住!在使用API类库的方法时,一定要先判断是否为null!例如:
if (news != null && news.length == 0) {}
android tips
标签:
原文地址:http://www.cnblogs.com/elementY/p/4427966.html