json 데이터 유니코드로 나올때 정보
json 데이터 유니코드로 나올때본문
ajax로 데이터 요청이 필요해서 작업하던 도중 데이터가 유니코드로 나와서
찾아서 수정한 내용 공유합니다. JSON_UNESCAPED_UNICODE
<?php
header("Content-Type:application/json");
$data = array();
$ttt = array();
$ttt['it_id'] = 'itid';
$ttt['it_name'] = 'itname';
$ttt['it_bbb'] = '한글 이번엔';
$data['ttt']=$ttt;
$data['view']='aaa';
$data['answer']='bbb';
echo json_encode($data,JSON_UNESCAPED_UNICODE);
?>
{"ttt":{"it_id":"itid","it_name":"itname","it_bbb":"\ud55c\uae00 \uc774\ubc88\uc5d4"},"view":"aaa","answer":"bbb"}
{"ttt":{"it_id":"itid","it_name":"itname","it_bbb":"한글 이번엔"},"view":"aaa","answer":"bbb"}
추천
3
3
댓글 2개
추천요~ 저도 이것 때문에 고생한 적이 있거든요~~
전 몇일 전 고민했던 부부인데
역슬래쉬 등의 문제로
응답 :
echo json_encode($data);
걍 이렇게 처리 하고
요청단에서
<script>
String.prototype.stripSlashes = function(){
return this.replace(/\\(.)/, "$1");
}
...
...
...
$.each( data.items, function( i, item ) {
item.image_url.stripSlashes()
}
</script>
이렇게 처리했습니다.
한글 유니코드는 잘 나오던데용...
역슬래쉬 등의 문제로
응답 :
echo json_encode($data);
걍 이렇게 처리 하고
요청단에서
<script>
String.prototype.stripSlashes = function(){
return this.replace(/\\(.)/, "$1");
}
...
...
...
$.each( data.items, function( i, item ) {
item.image_url.stripSlashes()
}
</script>
이렇게 처리했습니다.
한글 유니코드는 잘 나오던데용...