JSON.stringify()不转义撇号 [英] JSON.stringify() not escaping apostrophe

查看:936
本文介绍了JSON.stringify()不转义撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...使用JSON2.js和JQUERY

...using JSON2.js and JQUERY

从第一张图片中可以看到,对象属性 customerReport.Title 具有撇号.在代码中,您可以看到我正在将JSON.stringify()调用为 reportAsJson 字符串,而该字符串仍然具有未转义的撇号.

as you can see from the first image the object property customerReport.Title has an apostrophe. In the code you can see that I'm calling JSON.stringify() into reportAsJson string which still has the unescaped apostrophe.

$.ajax()返回的错误是{"Message":"Invalid object passed in, \u0027:\u0027 or \u0027}\u0027 expected. ...

the error returned by $.ajax() is {"Message":"Invalid object passed in, \u0027:\u0027 or \u0027}\u0027 expected. ...

最初,我只是要禁止用户使用撇号,但是我认为JSON.stringify()处理了此问题,还是我需要设置一些选项???

Initially I'm just going to ban apostrophe's from the user, but I thought JSON.stringify() handled this or do I need to set some option????

谢谢

推荐答案

您可以避免删除这些撇号,将其替换为HTML实体'-,即单引号-然后在客户端或服务器端解码HTML实体.

You can avoid removing these apostrophes replacing them with an HTML entity ' - that's a single quot - and later decode HTML entities either in the client or server-side.

这篇关于JSON.stringify()不转义撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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