lua表经过cjson encode 会把/ 转为\/,请教下有没有解决方法

715 views
Skip to first unread message

jiangfei

unread,
May 27, 2012, 1:47:27 PM5/27/12
to openresty, age...@gmail.com
比如:lua中一个表:
local tab = {url="http://www.google.com/group""}
经过cjson encode 后 / 全部变为 \/
请教下有没有解决办法?

jiangfei

unread,
May 27, 2012, 2:01:59 PM5/27/12
to openresty
已解决,谢谢
解决方法:
jsonstr=string.gsub(jsonstr,"\\","")
总觉得这方法有点土...

agentzh

unread,
May 27, 2012, 9:35:48 PM5/27/12
to jiangfei, openresty
Hello!

2012/5/28 jiangfei <liujiang...@gmail.com>:

JSON 字符串中的 \/ 为合法转义序列,见 json.org 主页上的 JSON 格式的文法定义:

http://json.org/

比如 Perl 世界的 JSON::XS 库在就可以正确解码 JSON 字符串中的 \/ 序列。

而你通过 string.gsub(jsonstr,"\\","") 处理过的 JSON 将很可能不再是合法的 JSON 字符串。

Regards,
-agentzh

jiangfei

unread,
May 28, 2012, 1:30:30 AM5/28/12
to openresty

学些了呵呵
On 5月28日, 上午9时35分, agentzh <agen...@gmail.com> wrote:
> Hello!
>
> 2012/5/28 jiangfei <liujiangfei.di...@gmail.com>:

Wendal Chen

unread,
May 29, 2012, 9:30:11 AM5/29/12
to open...@googlegroups.com
\/ 不是标准的Json转义

2012/5/28 jiangfei <liujiang...@gmail.com>



--
Wendal Chen
GuangDong China

agentzh

unread,
May 29, 2012, 10:02:23 AM5/29/12
to open...@googlegroups.com
Hello!

On Tue, May 29, 2012 at 9:30 PM, Wendal Chen <wenda...@gmail.com> wrote:
> \/ 不是标准的Json转义
>

你的依据是什么呢?

\/ 确实是标准的 JSON 转义序列,可以参见 RFC 4627 中的 2.5. Strings 一节:

http://tools.ietf.org/html/rfc4627

还有 json.org 主页上的 JSON 文法定义也明确规定了 \/ 是合法的字符串转义序列:

http://json.org/

Regards,
-agentzh

Wendal Chen

unread,
May 29, 2012, 8:28:46 PM5/29/12
to open...@googlegroups.com
哦,sorry,记错了

2012/5/29 agentzh <age...@gmail.com>

Regards,
-agentzh

Reply all
Reply to author
Forward
0 new messages