Uncaught SyntaxError: Unexpected token o in JSON at position 1
var result = JSON.parse(str);
에서 아래와 같은 오류가 발생한다.
VM598:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse ()
at Object.success (write.do:587)
at u (jquery-3.3.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.3.1.min.js:2)
at k (jquery-3.3.1.min.js:2)
at XMLHttpRequest. (jquery-3.3.1.min.js:2)
이유는 str 이
{"sessiontime":1800,"success":true}
와 같이 들어가야 하는데
아래와 같이 들어갔기 때문이다.
{sessiontime: 1800, success: true}
java에서 map을 @ResponseBody 를 통해 return 을 받는 경우 " 이 아래와 같이 text를 받는다.
{sessiontime: 1800, success: true}
ObjectMapper 를 써서 map을 String 으로 변환해서 받는 경우에는 "가 잘 들어가 있다.
다만, 생각 또는 확인해볼 부분이 존재하는데.
기존에는 ObjectMapper 를 쓰지 않고도 정상적으로 잘 동작하고 있었다.
그래서 jquery 버전의 문제인지.. 혹은.. 다른 무엇 때문인지는 아직 잘 모르겠다.
어쨎거나 ObjectMapper를 이용해서 해결함.
ObjectMapper 사용법은 아래 URL 참고
https://web-obj.tistory.com/216
VO 를 json으로 변경(VO를 String으로 변경)
VO를 String으로 변경할 일이 생겼다. VO --> JSON --> String으로 변경하는 방법을 선택하게 되었다. 1. com.fasterxml.jackson.core 라이브러리 등록 전자정부프레임워크에 기본적으로 들어있어서 따로 등록하지..
web-obj.tistory.com