惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Latest news
Latest news
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
V
V2EX
博客园 - 司徒正美
B
Blog RSS Feed
AWS News Blog
AWS News Blog
MyScale Blog
MyScale Blog
Scott Helme
Scott Helme
Cisco Talos Blog
Cisco Talos Blog
Last Week in AI
Last Week in AI
NISL@THU
NISL@THU
博客园 - Franky
P
Proofpoint News Feed
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
S
Schneier on Security
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
WordPress大学
WordPress大学
The Hacker News
The Hacker News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
罗磊的独立博客
T
The Blog of Author Tim Ferriss
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
K
Kaspersky official blog
SecWiki News
SecWiki News
云风的 BLOG
云风的 BLOG
美团技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Security Latest
Security Latest
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog
S
Security Affairs

博客园 - 举重-若轻

Survey 2遍的解决办法 Error occurred in deployment step 'Activate Features': Feature with Id 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' is not installed in this farm using powershell to change the some sub-webs' system master page AssetUrlSelector export to excel 用powershell更新user profile service中的一个字段 create a 全局临时表 Generate a random integrater Remote Debugging GAC'd Assemblies in SharePoint get all user profiles redirecting to custom user profile page css的em概念 异步调用的一个例子 CSS备忘 SharePoint 资料 Server.MapPath方法的应用方法 JSON的客户端和服务器操作 jquery 参考材料 备忘 用powershell更新user的display name
.NET种Json时对单引号和特殊字符串的处理
举重-若轻 · 2012-09-27 · via 博客园 - 举重-若轻

在Asp.NET的Json处理中,通常会遇到使用单引号或其他特殊字符,如果直接使用,会截断Json数据,造成JS错误无法正确运行。

其实只要使用Javascript的escape方法编码字符串后就可以解决这个问题。

但是在C#代码中怎么解决这个问题呢?

我们自然就想到了使用Server.UrlEncode方法来编码数据,可是实践后发现编码后的有些字符在JS中无法被unescape方法还原。

其实解决方法很简单,引用Microsoft.JScript程序集后,使用GlobalObject类的escape方法就行了。

这个方法作用和Server.UrlEncode类似,但是它相当于是在C#代码里调用了javascript的escape方法,自然而然可以保证能被unescape方法还原。

.cs中

1 Microsoft.JScript.GlobalObject.escape(strJS)

.js中

var csStr = unescape(json.csStr)

要先添加引用
添加引用--".NET"选项卡---"Microsoft.JScript"和"Microsoft.Vsa"加入之后

才能去使用using

另: 

可以 用replace解决里面包含单引号的问题?

Quote from:http://www.jiaonan.tv/html/blog/1/28008.htm