JSON:为什么正斜线逃脱了? [英] JSON: why are forward slashes escaped?

查看:106
本文介绍了JSON:为什么正斜线逃脱了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之所以逃避我。

JSON 转义正斜杠,因此散列 {a:a / b / c} 被序列化为 {a: a \ / b\ / c} 而不是 {a:a / b / c}

JSON escapes the forward slash, so a hash {a: "a/b/c"} is serialized as {"a":"a\/b\/c"} instead of {"a":"a/b/c"}.

为什么?

推荐答案

JSON不要求你这样做,它允许你这样做。它还允许您将\ u0061用于A,但这不是必需的。在< script> 标记中嵌入JSON时,允许 \ / 有帮助,但不允许< / 在字符串内部,比如Seb指出。

JSON doesn't require you to do that, it allows you to do that. It also allows you to use "\u0061" for "A", but it's not required. Allowing \/ helps when embedding JSON in a <script> tag, which doesn't allow </ inside strings, like Seb points out.

Microsoft的一些ASP.NET Ajax / JSON API使用这个漏洞来添加额外信息,例如,日期时间将以\ / Date(毫秒)\ /的形式发送。 (哎呀)

Some of Microsoft's ASP.NET Ajax/JSON API's use this loophole to add extra information, e.g., a datetime will be sent as "\/Date(milliseconds)\/". (Yuck)

这篇关于JSON:为什么正斜线逃脱了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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