首页 » 资源分享 » PHP » 正文

PHP如何正确使用 json_decode()解析JSON.stringify



经常我们会使用 JSON.stringify() 保存某些数据,然后需要在php中读取,但在PHP接到这个参数的数据时,使用json_decode()却无法解析。
所以问题就是,为什么json_decode()解析JSON.stringify为什么为NULL。
解决方法:
当你使用 JSON stringify时,先在json_decode前使用 html_entity_decode。

代码示例:

$tempData = html_entity_decode($tempData);
$cleanData = json_decode($tempData);