Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
736 views
in Technique[技术] by (71.8m points)

asp.net mvc - JsonResult parsing special chars as u0027 (apostrophe)

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

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

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, ...).

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

In the MVC3 controller, the apostrophes appear as u0027.

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

Example response: WCF Rest: {"CategoryId":8,"SomeId":6,"Name":"Richie's House"}

MVC3: {"CategoryId":8,"SomeId":6,"Name":"Richieu0027s House"}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

alerts Richie's House.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...