일상 기록 창고

JSON 파싱하기 본문

프로그래밍/Spring (jsp)

JSON 파싱하기

Crazy_Kong 2017. 2. 14. 18:15

1. pom.xml 설정


<dependency>

    <groupId>com.googlecode.json-simple</groupId>

    <artifactId>json-simple</artifactId>

    <version>1.1.1</version>

</dependency>



2. 간단사용법


{"msg":"OK","files":[{"sFileName":"s5711487049840.png","sOrgFileName":"4.png","sFileSize":37727,

"sFilePath":"\/\/localhost\/kong\/s5711487049840.png","sImage":{"0":994,"1":609,"2":3,"3":"width=\"994\"

height=\"609\"","bits":8,"mime":"image\/png"}}]}



msg 접근해서 가져오기


JSONObject obj = new JSONObject(AccountSendUrl);

String isOK = obj.getString("msg").toString();



files 접근해서 가져오기


JSONArray arr = obj.getJSONArray("files");

String sFilePath = arr.getJSONObject(0).get("sFilePath").toString();