develop/web GIS

OpenLayers addfeatures(json) 에서 json형식 java에서 만들기

hybr1d 2014. 11. 17. 19:24


public class IndexControl {

IndexCode indexCode ;

SbbDBMapper sbbMapper;

public List<IndexCode> getIndexCode(HttpServletResponse response) throws Exception {

DBUtils dbUtils = new DBUtils();

List<IndexCode> getIndex = dbUtils.selectList(DB.SBB_DB, "getIndexCode"); 

JSONObject jsonObj= new JSONObject();

JSONObject jsonObj1= new JSONObject();

JSONObject jsonObj2= new JSONObject();

JSONObject jsonObj3= new JSONObject();

JSONArray jsonArray = new JSONArray();

for(int i=0; i<getIndex.size(); i++) {

jsonObj1.put("type", "Feature");

jsonObj1.put("geometry", jsonObj2);

jsonObj2.put("type", "Point");

jsonObj2.put("coordinates", getIndex.get(i).getLat());

jsonObj1.put("properties", jsonObj3);

jsonObj3.put("location",getIndex.get(i).getStnKo());

jsonArray.put(jsonObj1);

}

jsonObj.put("features", jsonArray);

System.out.println("jsonObj : " +jsonObj);

response.setContentType("application/x-json; charset=UTF-8");

response.getWriter().print(jsonObj); 

return getIndex;

}

}