1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
package com.example.demo; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import java.io.*; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); ObjectMapper objectMapper = new XmlMapper(); try { JSONParser parser = new JSONParser(); // JSON 파일 읽기 Reader reader = new FileReader("sample.json"); JSONObject jsonObject = (JSONObject) parser.parse(reader); String name = (String) jsonObject.get("test"); System.out.println("파싱 결과 : "); // OK System.out.println(name); // OK } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (ParseException e) { throw new RuntimeException(e); } } } |
결과
1 2 3 4 |
파싱 결과 : OK |