gson解析json 出错
解析方法Gsongson=newGson();child_List=gson.fromJson(json,newTypeToken<List<CommType>>(){}...
解析方法
Gson gson = new Gson();
child_List = gson.fromJson(json,
new TypeToken<List<CommType>>() {
}.getType());
----------------------json数据
[ {"childs": [ { "childs": [],"color": "", "id": "8","name": "中餐", },
{ "childs": [], "color": "", "id": "9", "name": "西餐", }
], "color": "","id": "2", "name": "餐饮美食", }, { "childs": [], "color": "","id": "3", "name": "休闲娱乐", },
{"childs": [], "color": "","id": "4", "name": "便民服务", },
{ "childs": [], "color": "","id": "5","name": "酒店旅游", },
{ "childs": [], "color": "", "id": "6","name": "美容保健", },
{ "childs": [ { "childs": [
{"childs": [],"color": "","id": "12", "name": "项链", } ], "color": "", "id": "10", "name": "服装",},
{"childs": [ { "childs": [],"color": "","id": "13", "name": "帽子",} ], "color": "", "id": "11", "name": "饰品", } ],
"color": "","id": "7", "name": "购物服饰", }
]
---------------------------------类
public static class CHILDS {
private String childs;
private String color;
private int id;
private String name;
private String path;
private int pid;
}
private List<CHILDS> childs;
public List<CHILDS> getChilds() {
return childs;
}
public void setChilds(List<CHILDS> childs) {
this.childs = childs;
}
private String color;
private int id;
private String name;
public String getColor() {
return color;
} 展开
Gson gson = new Gson();
child_List = gson.fromJson(json,
new TypeToken<List<CommType>>() {
}.getType());
----------------------json数据
[ {"childs": [ { "childs": [],"color": "", "id": "8","name": "中餐", },
{ "childs": [], "color": "", "id": "9", "name": "西餐", }
], "color": "","id": "2", "name": "餐饮美食", }, { "childs": [], "color": "","id": "3", "name": "休闲娱乐", },
{"childs": [], "color": "","id": "4", "name": "便民服务", },
{ "childs": [], "color": "","id": "5","name": "酒店旅游", },
{ "childs": [], "color": "", "id": "6","name": "美容保健", },
{ "childs": [ { "childs": [
{"childs": [],"color": "","id": "12", "name": "项链", } ], "color": "", "id": "10", "name": "服装",},
{"childs": [ { "childs": [],"color": "","id": "13", "name": "帽子",} ], "color": "", "id": "11", "name": "饰品", } ],
"color": "","id": "7", "name": "购物服饰", }
]
---------------------------------类
public static class CHILDS {
private String childs;
private String color;
private int id;
private String name;
private String path;
private int pid;
}
private List<CHILDS> childs;
public List<CHILDS> getChilds() {
return childs;
}
public void setChilds(List<CHILDS> childs) {
this.childs = childs;
}
private String color;
private int id;
private String name;
public String getColor() {
return color;
} 展开
2个回答
2014-06-30
展开全部
childs 这个重复估计不行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询