반응형 Map2 [JAVA] 자바 json 문자열로 변환하기 자바에서 Map 또는 배열을 json 문자열로 변환하기 # Map을 json 문자열로 변환 import com.fasterxml.jackson.databind.ObjectMapper; Map map = new HashMap(); map.put("A", "1"); map.put("B", "2"); map.put("C", "3"); ObjectMapper jsonMapper = new ObjectMapper(); String jsonStr = jsonMapper.writeValueAsString(map); System.out.println(jsonStr); // {"A":"1","B":"2","C":"3"} 2023. 5. 1. [JAVA] List map에서 데이터 가져오기 List Map에서 데이터 가져오기 Map map = new HashMap(); List list = new ArrayList(); map.put("one", "1"); map.put("two", "2"); map.put("three", "3"); list.add(map); for(int i = 0; i < list.size(); i++){ System.out.println("list 사이즈 :" + i); System.out.println("list entrySet :" + list.get(i).entrySet()); for( Map.Entry elem : list.get(i).entrySet() ){ // list 각각 hashmap받아서 출력 if(elem.getValue() != null && e.. 2023. 4. 30. 이전 1 다음 반응형