REST API 사용하다 필요해서 알아보니 org.json 패키지를 추가하면 사용할 수 있다고 한다.
Maven Repository: org.json » json
JSON is a light-weight, language independent, data interchange format. See http://www.JSON.org/ The files in this package implement JSON encoders/decoders in Java. It also includes the capability to convert between JSON and XML, HTTP headers, Cookies, and
mvnrepository.com
pom.xml에 추가
<!-- JSON -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
사용하기!
String strJson = "{\"name\": \"StephenCurry\"}";
JSONObject jsonObj = new JSONObject(strJson);
String name = jsonObj.getString("name");
+) 참고
How to parse JSON in Java
I have the following JSON text. How can I parse it to get the values of pageName, pagePic, post_id, etc.? { "pageInfo": { "pageName": "abc", "pagePic": "http://example.com/con...
stackoverflow.com
'STUDY > Spring' 카테고리의 다른 글
Spring Boot | multipart/form-data 파일 업로드 ( + React , Axios, REST API, multiple files) (1) | 2020.10.19 |
---|---|
Spring | Illegal overloaded getter method (0) | 2020.10.12 |
Spring Boot | JWT를 사용하는 Spring Security 로그인 ( REST API ) (4) | 2020.10.07 |
Spring | properties 사용하기 (0) | 2020.07.09 |
Spring | 파일 업로드 ( + Spring Security ) (0) | 2020.07.06 |