๋ฐ์ํ
- JAVA์์ JSON ํ์ฑํ๊ธฐ
JSONParser : https://javaee.github.io/javaee-spec/javadocs/javax/json/stream/JsonParser.html
JSONObject : https://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html
1. json-simple.jar ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ค์ด๋ก๋ & ์ค์
๋ค์ด๋ก๋ ์ฃผ์ : https://code.google.com/archive/p/json-simple/downloads
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
2. ์ฝ๋ ๊ตฌํ
// {"Json1":"test1","Json2":"test2"}
String testTxt = "{\"Json1\":\"test1\",\"Json2\":\"test2\"}";
JSONParser parser = new JSONParser();
JSONObject jsonObj = null;
try{
jsonObj = (JSONObject) parser.parse(testTxt);
String str1 = (String)jsonObj.get("Json1");
String str2 = (String)jsonObj.get("Json2");
System.out.println("Json1 : " + str1);
System.out.println("Json2 : " + str2);
}catch(ParseException e){
// ๋ณํ์คํจ
System.out.println("JSON parsing failed !");
e.printStackTrace();
}
get ์ด์ฉ์, ์
๋ ฅ ๋ณ์ key ๊ฐ์ value ๊ฐ์ ๊ฐ์ ธ์ต๋๋ค.
์๋์ ๊ฐ์ ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ๋ฉ๋๋ค.
Json1 : test1
Json2 : test2
๋ฐ์ํ
'Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] javax.net.ssl.SSLHandshakeException: connection during handshake (0) | 2022.03.23 |
---|---|
[Java] log4j Log ๋ ๋ฒจ (0) | 2022.01.07 |
[Java] Reflection์ ์ด์ฉํ private ์ ๊ทผํ๊ธฐ (2) | 2021.12.23 |
[Java] jar ํ์ผ ์์ฑํ๊ธฐ (Eclipse / bat ํ์ผ) (1) | 2021.12.16 |
[Java] ๊ฐ์ ๋๋ฉ์ธ ์ฌ์ฉ์ session๊ฐ null๋ก ๋ณ๊ฒฝ๋๋ ํ์ (2) | 2021.12.10 |
๋๊ธ