Web/Javascript
[Javascript] JSON.parse, JSON.stringify 차이 / 예제
나비와꽃기린
2016. 7. 7. 10:41
DATA 출력 결과에서 매번 삐끄덩 거린다 -_-;;
정리해놓고 보자! (LIST -> JSON)
http://mkil.tistory.com/category/Java/Java 휴...................
parse 는 string 개체를 json 개체로, stringify 는 json 개체를 string 개체로 변환시켜 준다 !!!!
console.log('${list.items}')
다음과 같은 Data로 테스트를 해보자.
[{"INDN":"20000000","ORG_NM":"Consumer Insurance","PSN_NAME":"홍길동","PZC_NM":null}] |
--> 이 결과값을 받아 $(‘${list.items}’).each(function(i,item)
for문 돌리려니 syntax error 발생한다. 이유는 string이기 떄문.
console.log(JSON.parse('${list.items}')) 결과
다음과 같이 JSON 객체로 바뀐걸 확인할 수 있다
(3) console.log(JSON.stringify('${list.items}')) 결과
"[{\"INDN\":\"20000000\",\"ORG_NM\":\"Consumer Insurance\",\"PSN_NAME\":\"홍길동\",\"PZC_NM\":null}]" |