JSON控制字符错误,没有控制字符 [英] JSON control character error, without a control character

查看:103
本文介绍了JSON控制字符错误,没有控制字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSON将数据从服务器传输到客户端,反之亦然.我使用LZString压缩聊天消息字符串以节省空间.除4个字符的消息(例如"abcd","xyzs"等)外,此方法都可以正常工作.
一切工作正常,但JSON无法正确解码.我的PHP代码(通过json_last_error_msg检查)告诉我我有

Im using JSON to transfer data from my server to my client and vice versa. I compress chat message strings with LZString to save space. This works fine, except for 4 character messages (so "abcd", "xyzs" etc).
Everything works fine, but the JSON doesn't get decoded correctly. My PHP code (checked via json_last_error_msg) tells me that I have a

Control character error, possibly incorrectly encoded

所以我检查了一下,看来控制字符主要是格式问题,例如换行符,制表符等.
我用JSONLint检查了我的JSON,它说的很好,所以我真的不知道错误在哪里.以下是带有4个字符的消息的JSON输出示例:

So I checked and it seems that control characters are mainly formatting issues, like line breaks, tabs etc.
I checked my JSON with JSONLint and it says its fine, so I really don't know where the error lies. Heres a sample JSON output with a 4 character message:

{ "code": "CHAT_SEND_MESSAGE", "args": ["ALL","ÒÄçþéåÓ╣ñ "]}

在args中字符串末尾的空格似乎是错误的.因为大约有4个字符符号(例如"Ôåä´ìÇ")起作用,而所有末尾带有空格的字符都会出现控制字符错误(例如ÔåéÒâå╔ñ"或以上消息).知道为什么会这样吗?

It seems to be an error with the space at the end of the string in args. Because some 4 character signs (like "Ôåä´ìÇ") work, while everything with a space at the end gives a control character error (like "ÔåéÒâå╔ñ " or the message above). Any idea why that is happening?

推荐答案

有控制字符,在您看来,它像一个空格.例如查看ASCII 0-31 http://ascii-code.com/

there are control characters, which seems to you like a space. for example have a look at the ASCII 0-31 http://ascii-code.com/

也许尝试将其复制粘贴到Windows编辑器(而不是Notepad ++或word)中,然后再粘贴回您的json数据中.

Maybe try to copy-paste into Windows Editor (not Notepad++ or word) and pasting back into your json data.

这篇关于JSON控制字符错误,没有控制字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆