redgoose(붉은거위)

json_encode(), json_decode()

Nest
Development
Category
PHP
Hit
642
Star
0

json_decode()를 사용할때 리턴값이 null로 나오는경우

"\"로 되어있을때 decode가 되지않는 현상이 발견되었다. 이에 대해서 해결방법은 아래 소스와 같다.

if(get_magic_quotes_gpc())
{
  $result = stripslashes($_POST['result']);
}
else
{
  $result = $_POST['result'];
}

$json = json_decode($result, true);

참고URL
http://www.evanconkle.com/2011/11/json_decode-returns-null-php/

json_encode를 사용할때 한글이 \ud55c\ud6a8\uc8fc 같이 출력될때..

다음과 같이 사용하면 해결됨.

echo json_encode($result, JSON_UNESCAPED_UNICODE);

출처
http://daehee.kim/m/post/150