[java] 자바에서 String을 json 객체로 변환하는 방법
java에서 String으로 돼 있는 json을 JSONObject로 변환해서 json을 사용하는 샘플예제입니다. 저도 이거 찾느라 한참을 뒤졌네요. import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser..
zzznara2.tistory.com
[JAVA] JSON library json-simple 사용법
json-simple 이란? JSON 데이터를 처리하기 위한 자바 라이브러리입니다. json-simple 특징 1.json-simple은 내부적으로 JSON 데이터를 처리하기 위해 Map과 List를 사용합니다. 2.json-simple은 JSON 데이터를 구..
tychejin.tistory.com
Maven 설정
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
String => json example code
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
String jsonStr = "{"
+ " code:'1000',"
+ " name:'포도'"
+ "}"
;
JSONParser parser = new JSONParser();
Object obj = parser.parse( jsonStr );
JSONObject jsonObj = (JSONObject) obj;
String code = (String) jsonObj.get("code");
String name = (String) jsonObj.get("name");
'시행착오 > [java]' 카테고리의 다른 글
[java] TimerTask에 파라미터 전달하기 (0) | 2021.04.08 |
---|---|
[java] HTTP request POST 보내는 법 - 예시 코드 / (추가) 한글깨짐 현상 해결 (0) | 2021.04.08 |