如何将json对象转换为以下类型
的java bean(Main Mean)class MainBean{
private int id;
private SubBean sBean;
}
class SubBean{
private String name;
private List<DBean> dBean;
}
答案 0 :(得分:4)
有很多库可以做到。Google-Gson
MainBean bean = new Gson().fromJson(yourJsonAsString, MainBean.class);
像这样的JSON将被很好地转换
{"id" : 1, "sBean" : {"name" : "beanname", "dBean" : []}}