tp5框架开启了html过滤,接收的json数据被转义

例子

1
2
3
4
5
6
//接收数据
$message = input('message');
//转义html标签,得到正确的json数据
$message = htmlspecialchars_decode($message);
//随后,json转数组
$array = json_decode($message, true);


前端传值
1
[{"id":1,"goods_price":"80","shop_id":1},{"id":2,"goods_price":"99","shop_id":1}]

后端接收数据

1
[{"id":1,"goods_price":"80","shop_id":1},{"id":2,"goods_price":"99","shop_id":1}]

处理方法
可以用函数htmlspecialchars_decodehtml_entity_decode进行转义,这样可以得到正确的json数据