json_encode, json_decode

유영·2024년 5월 29일
0

ajax

목록 보기
3/3

json_decode()
: Json 형식 문자열을
PHP Array 또는 String으로 변환하는 PHP 함수

json_encode()
:PHP Array 또는 String 을
Json String으로 묶어 반환하는 PHP 함수

PHP의 간단한 JSON 인코드 함수인 json_encode()는 유니코드 형태로
자동 출력해버리는 기능때문에 한글을 쓸 경우 유니코드 문자로서 나타난다.
하지만 PHP 5.5 버전부터는 2번째 파라미터에 JSON_UNESCAPED_UNICODE 값을 주면
간단히 해결할 수 있다.

$result = json_encode($json,JSON_UNESCAPED_UNICODE);
//slash escape 해결법과 함께
json_encode($json,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
//이런 식으로 사용하면 더욱 완벽하게 쓸 수 있다.

출처
https://itun.tistory.com/541
https://blog.naver.com/cokolavel/221516817104

0개의 댓글