JsonResult解析特殊字符为\\ u0027(单引号) [英] JsonResult parsing special chars as \u0027 (apostrophe)

查看:3673
本文介绍了JsonResult解析特殊字符为\\ u0027(单引号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从WCF休息转换我们的一些网站服务MVC3的过程。

I am in the process of converting some of our web "services" to MVC3 from WCF Rest.

我们的旧的Web服务返回的JSON使用POCO的就好了:
[WebGet(.... ResponseFormat = WebMessageFormat.Json]

Our old web services returned JSON from POCO's just fine using: [WebGet(.... ResponseFormat=WebMessageFormat.Json]

在我的控制器即可返回我使用JsonResult作为返回类型,并创建具有 JSON的一个简单的POCO JSO​​N(someObject,...)

In my controller to return back a simple poco I'm using a JsonResult as the return type, and creating the json with Json(someObject, ...).

在WCF REST服务,撇号和特殊字符的格式整齐时presented到客户端。

In the WCF Rest service, the apostrophes and special chars are formatted cleanly when presented to the client.

在MVC3控制器,撇号显示为\\ u0027。

In the MVC3 controller, the apostrophes appear as \u0027.

有什么想法?我是新来的JSON序列化这样的指针将是一个巨大的帮助。

Any thoughts? I'm new to serializing JSON so any pointers would be a huge help.

响应示例:
WCF休息:
{类别ID:8,SomeId:6,名称:里奇之家}

MVC3:
{类别ID:8,SomeId:6,名称:小齐\\提供上门屋}

推荐答案

这应该不是什么问题,因为这两个重presentations是等价的:

That shouldn't be any problem, as both representations are equivalent:

var a = {"CategoryId":8,"SomeId":6,"Name":"Richie\u0027s House"};
alert(a.Name);

提醒里奇之家

这篇关于JsonResult解析特殊字符为\\ u0027(单引号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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