Gson解析多层Json时出现的问题

张小贝_ 2016-07-23 09:44:02
数据接口http://www.fresheasy.cn/Api.php/GoodsClass/index
解析用的Volley方法
解析到第二层的时候数组取值会报错
resultCallBack=new ResultCallBack() {
@Override
public void callBackWithData(Object dataObject) {
//获取名字及数据
List<ClassifyModel> collection = (List<ClassifyModel>) dataObject;
int length = collection.size();
Log.i("Tag",collection.size()+"");
Log.i("Tag",collection.toString());
goodsnames = new String[length];
for (int i=0;i<length;i++){
goodsnames[i] = collection.get(i).getGc_name();
// Log.i("Tag",goodsnames.toString());
int length2 = collection.get(i).getCategoryitem().size();
Log.i("Tag",length2+"");
categorynames= new String[length2];
for (int j=0;j<length2;j++){
categorynames[j] = collection.get(i).getCategoryitem().get(j).getGc_name();
Log.i("Tag",categorynames.toString());
// int length3= collection.get(i).getCategoryitem().get(j).getChild().size();
// Log.i("Tag",length3+"");
// childnames = new String[length3];
// imageurl= new String[length3];
// for (int k=0;k<length3;k++){
// childnames[k] = collection.get(i).getCategoryitem().get(j).getChild().get(k).getGc_name();
// imageurl[k] = collection.get(i).getCategoryitem().get(j).getChild().get(k).getUrl();
// }
}
adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, goodsnames);
listviewnames.setAdapter(adapter);
}
报错地方在categorynames= new String[length2];这一句,求指点
...全文
240 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
秃头地中海 2016-07-23
  • 打赏
  • 举报
回复
看了你的数据,还是用gson解析比较方便,具体怎么用自己百度下 很简单的 另外这个是json在线视图查看器http://www.bejson.com/jsonviewernew/

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧