php json加空格,PHP Json_encode将空格更改为加号

我有一个Web应用程序,首先将JSON数据存储在cookie中,然后每隔x秒将其保存到数据库中.它只是打开与服务器的连接,服务器读取cookie.它实际上并不通过POST或GET发送任何内容.

当我保存到cookie时,我的数据格式良好.但是,当我在PHP中使用它,然后setcookie一个新的json_encoded数组时,它用符号替换了空格,然后这些出现在我的Web应用程序中.我找不到禁用json_encode字符串编码的任何方法,也没有找到解析那些加号的JS方法(使用jQuery.parseJSON; stringify的解析也不起作用)…没有人知道:S吗?

解决方法:

Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, it is automatically decoded and assigned to a variable by the same name as the cookie name. If you don’t want this, you can use setrawcookie() instead if you are using PHP 5.

但我认为您仍然希望对Cookie URL进行编码,只希望使用空格而不是.但是,urlencode:

[…] for historical reasons, spaces are encoded as plus (+) signs

您可以尝试使用rawurlencode自己对其进行编码:

Returns a string in which all non-alphanumeric characters except -_.~ have been replaced with a percent (%) sign followed by two hex digits. This is the encoding described in RFC 3986 […]

然后setrawcookie设置cookie.不幸的是,decodeURI、decodeURIComponent甚至不推荐使用的unescape JavaScript函数都不会将back转换为空格.因此,您可能会陷入困境,迫使每个人都难以理解.

标签:json,php,jquery

来源: https://codeday.me/bug/20191102/1990983.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值