tec*_*ant 4 php arrays cookies json encode
我正在尝试从cookie中解析一个JSON编码的字符串,当我对该字符串运行json_decode()时,它返回为null。这应该是一个简单的操作-我缺少什么?
/* Get */
$cookie_exampleData = $_COOKIE['exmaple_data'];
// Retrieves: '{\"FirstName\":\"Angus\",\"LastName\":\"MacGyver\",\"Email\":\"hello@email.com\",\"Phone\":\"8185555555\"}'
/* Decode */
$cookie_exampleData_decoded = json_decode($cookie_exampleData);
/* Print */
var_dump($cookie_exampleData_decoded);
// Returns: NULL
Run Code Online (Sandbox Code Playgroud)
在这种情况下,您需要删除转义的引号:
$cookie_exampleData = stripslashes($_COOKIE['exmaple_data']);
Run Code Online (Sandbox Code Playgroud)
参见反斜杠
| 归档时间: |
|
| 查看次数: |
4735 次 |
| 最近记录: |