经常我们会使用 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);
html_entity_decode(string,flags,character-set) 函数把 HTML 实体转换为字符,是 htmlentities() 函数的反函数。
string 必需。规定要解码的字符串。
flags
可选。规定如何处理引号以及使用哪种文档类型。
可用的引号类型:
ENT_COMPAT - 默认。仅解码双引号。
ENT_QUOTES - 解码双引号和单引号。
ENT_NOQUOTES - 不解码任何引号。
规定所使用文档类型的附加 flags:
ENT_HTML401 - 默认。作为 HTML 4.01 处理代码。
ENT_HTML5 - 作为 HTML 5 处理代码。
ENT_XML1 - 作为 XML 1 处理代码。
ENT_XHTML - 作为 XHTML 处理代码。
character-set
可选。字符串值,规定要使用的字符集。
允许的值:
UTF-8 - 默认。ASCII 兼容多字节的 8 位 Unicode
ISO-8859-1 - 西欧
ISO-8859-15 - 西欧(加入欧元符号 + ISO-8859-1 中丢失的法语和芬兰语字母)
cp866 - DOS 专用 Cyrillic 字符集
cp1251 - Windows 专用 Cyrillic 字符集
cp1252 - Windows 专用西欧字符集
KOI8-R - 俄语
BIG5 - 繁体中文,主要在台湾使用
GB2312 - 简体中文,国家标准字符集
BIG5-HKSCS - 带香港扩展的 Big5
Shift_JIS - 日语
EUC-JP - 日语
MacRoman - Mac 操作系统使用的字符集
注释:在 PHP 5.4 之前的版本,无法被识别的字符集将被忽略并由 ISO-8859-1 替代。自 PHP 5.4 起,无法被识别的字符集将被忽略并由 UTF-8 替代。
当前位置:网站首页>PHP处理json_decode()解析JSON.stringify
PHP处理json_decode()解析JSON.stringify
2022-04-23 05:39:00 【fusheng-fate】
版权声明
本文为[fusheng-fate]所创,转载请带上原文链接,感谢
https://blog.csdn.net/lgb1997/article/details/108489770
边栏推荐
- Differences between auto and decltype inference methods (learning notes)
- World and personal development
- The address value indicated by the pointer and the value of the object indicated by the pointer (learning notes)
- windows连接mysql出现ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost‘ (10061)
- Membarrier (personal learning and understanding)
- Interview Basics
- On the use of constant pointer and pointer constant -- exercise (record)
- JSON.
- Frequently asked interview questions - 2 (computer network)
- Markdown syntax support test
猜你喜欢
Hongji micro classroom | cyclone RPA's "flexible digital employee" actuator
Hongji | how does HR carry out self change and organizational change in the digital era?
2-軟件設計原則
3d slicer中拉直体的生成
Excel sets row and column colors according to cell contents
Common protocols of OSI layer
弘玑Cyclone RPA为国金证券提供技术支撑,超200个业务场景实现流程自动化
Sea Level Anomaly 和 Sea Surface Height Anomaly 的区别
橙单微服务之批量导入
Jiugong magic square - the 8th Lanqiao provincial competition - group C (DFS and comparison of all magic square types)
随机推荐
poi导出excel,行相同数据自动合并单元格
Typescript interface & type rough understanding
热键,界面可视化配置(界面交互)
Step on the pit: Nacos uses startup CMD - M standalone startup error
Xiuxian real world and game world
Rog attack
[no title] Click the classification jump page to display the details
MySQL query uses \ g, column to row
refused connection
Fast application fuzzy search
Shell instruction learning 1
Map object map get(key)
Golang通过exec模块实现Ping连通性检测案例
QT compressed folder
转置卷积(Transposed Convolution)
Several examples of pointer transfer, parameter transfer, value transfer, etc
Breadth first search topics (BFS)
QT drawpixmap and DrawImage blur problem
The 8th Blue Bridge Cup 2017 - frog jumping cup
Error 2003 (HY000) when Windows connects MySQL: can't connect to MySQL server on 'localhost' (10061)