ObjectMapper ๋ฅผ ๋ฐฐ์ฐ๋ฉด์ Json ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฃจ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ฐ๋ค ์๊ฒ๋ String ๋ฌธ์์ด Json ๋ณํ ๋ฐฉ๋ฒ์ด๋ค.
 
Maven ์ค์ 
pom.xml
<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1.1</version>
</dependency>
 
String ๋ฌธ์์ด Json ๋ณํ
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
 
public class StringToJson {
    public static void main(String[] args) throws ParseException {
 
        // JSON ์ผ๋ก ํ์ฑํ  ๋ฌธ์์ด
        String str = "{\"name\" : \"apple\", \"id\" : 1, \"price\" : 1000}";
 
        // JSONParser๋ก JSONObject๋ก ๋ณํ
        JSONParser parser = new JSONParser();
        JSONObject jsonObject = (JSONObject) parser.parse(str);
 
        // JSON ๊ฐ์ฒด์ ๊ฐ ์ฝ์ด์ ์ถ๋ ฅํ๊ธฐ
        System.out.println(jsonObject); // {"price":1000,"name":"apple","id":1}
        System.out.println(jsonObject.get("name")); // apple
        System.out.println(jsonObject.get("id")); // 1
        System.out.println(jsonObject.get("price")); // 1000
 
    }
}
 
 
 
์ถ์ฒ | hi.anna