STUDY/Spring
Spring | JSON 사용하기 ( org.json )
개미606
2020. 10. 7. 18:00
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