这是我的代码,我使用投影只显示特定的列,我得到的结果为array.But我希望输出为json
我该怎么做才能将输出作为{{1} }。
请帮帮我
json
我正在获得的输出
public List<Educationlevel> getAllEducationlevel() {
Session session = SessionFactoryUtil.getSessionFactory().openSession();
try {
session.beginTransaction();
Criteria criteria = session.createCriteria(Educationlevel.class);
ProjectionList projlist =Projections.projectionList();
projlist.add(Projections.property("education_level"));
projlist.add(Projections.property("education_level_id"));
projlist.add(Projections.property("country_id"));
criteria.add(Restrictions.eq("delete_flag", false));
criteria.setProjection(projlist);
return criteria.list();
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
session.getTransaction().commit();
session.close();
}
}
和我期待的输出 在这里,我想只有3列说education_level_id,country_id,education_level
[["PG",0,2],["PHD",1,2]]
答案 0 :(得分:0)
JSONObject jo = new JSONObject();
jo.put("education_level", "PG");
jo.put("education_level_id", "0");
JSONArray ja = new JSONArray();
ja.put(jo);