당신의 전 :
print_r($cookie);
해야 할 것 :
json_last_error();
아무 것도 반환하지 않습니까? 빈 화면이 나타나면 파서가 작동하지 않아 쿠키 내의 json 문자열에있는 "
의 결과가 \"
으로 이스케이프 처리 된 것일 수 있습니다. 시도 :
$cookie = json_decode(stripslashes($_COOKIE['TestCookie']));
업데이트
그래서 나는 다음과 같은 코드를 사용하고, 다음과 같은 출력받은 : 당신이 경우
$value = array(
'utm_source' => 'website',
'utm_medium' => 'fbshare',
'utm_campaign' => 'camp1',
'test_cat' => 'red',
'test_sub' => 'Category',
'test_ref' => 'rjdepe'
);
var_dump($value);
setcookie('TestCookie', json_encode($value), time()+86400);
echo $_COOKIE['TestCookie'];
print_r(json_decode($_COOKIE['TestCookie']));
출력
array(6) {
["utm_source"]=>
string(7) "website"
["utm_medium"]=>
string(7) "fbshare"
["utm_campaign"]=>
string(5) "camp1"
["test_cat"]=>
string(3) "red"
["test_sub"]=>
string(8) "Category"
["test_ref"]=>
string(6) "rjdepe"
}
{
"utm_source":"website",
"utm_medium":"fbshare",
"utm_campaign":"camp1",
"test_cat":"red",
"test_sub":"Category",
"test_ref":"rjdepe"
}
stdClass Object
(
[utm_source] => website
[utm_medium] => fbshare
[utm_campaign] => camp1
[test_cat] => red
[test_sub] => Category
[test_ref] => rjdepe
)
을 통지, 인코딩 된 배열입니다. json 문자열은 문자열입니다. 디코딩 된 문자열은 객체입니다.
당신은 배열이 캐스팅 입력 할 수 있습니다
: 또한
$value = (array) json_decode($_COOKIE['TestCookie']);
// Or
$value = json_decode($_COOKIE['TestCookie'], true);
,
구성에 따라, PHP는 JSON 디코딩 오류가 무엇 것 같다 쿠키에 특수 문자를 탈출 할 수있다 중계. 일을
시도 :
json_decode(str_replace('\"', '"', $_COOKIE['TestCookie']), true);
우리는 어떻게 당신의 ** 정확한 ** 코드를 추측 해야하는? – zerkms
@dqlopez :'print_r'의 결과입니다 – zerkms
어떻게했는지 코드를 보여주십시오? – xdazz