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

推荐订阅源

D
Docker
G
Google Developers Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
V
Vulnerabilities – Threatpost
Hugging Face - Blog
Hugging Face - Blog
I
Intezer
S
Securelist
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
Y
Y Combinator Blog
N
News | PayPal Newsroom
S
Schneier on Security
O
OpenAI News
T
The Blog of Author Tim Ferriss
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
Martin Fowler
Martin Fowler
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
N
News and Events Feed by Topic
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
The Cloudflare Blog
Last Week in AI
Last Week in AI
博客园 - 司徒正美
L
LangChain Blog
C
CERT Recently Published Vulnerability Notes
L
LINUX DO - 热门话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Hacker News
The Hacker News
博客园 - Franky
Attack and Defense Labs
Attack and Defense Labs
Security Latest
Security Latest
T
Tailwind CSS Blog
博客园_首页
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Security Blog
Microsoft Security Blog
V2EX - 技术
V2EX - 技术
腾讯CDC
V
V2EX

博客园 - 举重-若轻

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