오늘 일하면서 고급정보를 얻었다
바로 JSON 값을 맵 형태로 바꾸어 키값과 밸류값을 두가지 를 얻을 수 있다는 점이다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | CommonMap resultMap = new CommonMap(); ObjectMapper objectMapper = new ObjectMapper(); try { resultMap = (CommonMap)objectMapper.readValue(schedulerInfo, CommonMap.class); } catch (Exception e) { e.printStackTrace(); } System.out.println(resultMap); Set a = resultMap.keySet(); Iterator i = a.iterator(); while(i.hasNext()){ //System.out.println(resultMap.get(i.next())); LinkedHashMap tmp = (LinkedHashMap)resultMap.get(i.next()); CommonMap tmpResult = new CommonMap(); String start_date = (String) tmp.get("start_date"); String end_date = (String) tmp.get("end_date"); tmpResult.put("start_date", CommonUtil.getCalendarDay(start_date)); tmpResult.put("end_date", CommonUtil.getCalendarDay(end_date)); tmpResult.put("text", tmp.get("text")); tmpResult.put("subject", tmp.get("subject")); int insertResult = service.insertResult(tmpResult); | cs |
ObjectMapper objectMapper = new ObjectMapper();
ObjectMapper
Json 을 오브젝트로 만들어 준다는건데 원리는 잘 알겠지만 생각보다 어렵다...
암튼 키셋을 이용하면 키가 뽑히고 readVaue하면 밸류값이 뽑힌다.
나머지는 현재 프로젝트 명이므로 CommonMap 대신 HashMap을 쓰면 되겠다. 이상.
'IT·인터넷' 카테고리의 다른 글
티스토리 애드센스 완전히 승인 완료! (6) | 2016.02.25 |
---|---|
[HTML]모바일 토글 드롭다운 버튼 및 메뉴 버튼 (2) | 2016.02.19 |
티스토리 네이버 검색유입 된다. (0) | 2015.07.01 |
jquery 엔터키 이벤트(enterEvent Key) 처리 하는법 (2) | 2015.06.30 |
input disabled 타입을 ajax form 형식으로 보내기 (0) | 2015.06.27 |
댓글