1个回答
展开全部
String jsonStr = "[{'id':'11','parentId':'root','refObj':{'existType':'exist','deptType':'emp','treeNodeType':'dept'}}]";
Gson gson = new Gson();
Type type = new TypeToken<List<Bean>>() {
}.getType();
List<Bean> list = gson.fromJson(jsonStr, type);
更多追问追答
追问
但是在里层还有集合不能解析啊
追答
你在建对象的时候就要把层级关系建立好,根据json字符串来建立,每个字段都要一致就可以了
class Bean {
private String id;
private String parentId;
private RefObj refObj;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public RefObj getRefObj() {
return refObj;
}
public void setRefObj(RefObj refObj) {
this.refObj = refObj;
}
}
class RefObj {
private String existType;
private String deptType;
private String treeNodeType;
public String getExistType() {
return existType;
}
public void setExistType(String existType) {
this.existType = existType;
}
public String getDeptType() {
return deptType;
}
public void setDeptType(String deptType) {
this.deptType = deptType;
}
public String getTreeNodeType() {
return treeNodeType;
}
public void setTreeNodeType(String treeNodeType) {
this.treeNodeType = treeNodeType;
}
}
这就是刚才那段代码中的对象,你仔细看看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询