{
"website": {
"1": {
"basic": {
"homepage": "http://pythontip.sinaapp.com/",
"homename": "Python之禅--大道至简"
},
"list": {
"2": {
"childpage": "http://pythontip.sinaapp.com/study/books/pythontutorial3-master",
"chilename": "Python 入门指南"
},
"3": {
"childpage": "http://pythontip.sinaapp.com/coding/code_oj",
"chilename": "挑战Python"
}
}
}
}
}
我使用的是Google的Gson对其做解析,下载gson jar包
import java.io.Serializable;
public class ChildPage implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String childpage;
private String chilename;
//getter and setter
@Override
public String toString() {
return "ChildPage [childpage=" + childpage+ ", chilename=" + chilename + "]";
}
}
import java.io.Serializable;
public class ParentPage implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String hostpage;
private String homename;
//getter and setter
@Override
public String toString() {
return "ParentPage [homepage=" + homepage+ ", homename=" + homename + "]";
}
}
import java.io.Serializable;
import java.util.HashMap;
public class ParentAndChildPage implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private ParentPage basic;
private HashMap list;
//getter and setter
@Override
public String toString() {
return "ParentAndChildPage [basic=" + basic + ", list=" + list + "]";
}
}
import java.io.Serializable;
import java.util.HashMap;
public class Website implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private HashMap website;
//getter and setter
@Override
public String toString() {
return "Website [website=" + website + "]";
}
}
Website website = new Gson().fromJson(json, Website.class);
注意:Java Bean的属性必须和Json串的key值对应。