【发布时间】:2014-02-27 18:52:47
【问题描述】:
我有以下 JSON 格式的 c# 字符串。
string myString = "{color: \"red\", value: \"2\"}";
当我将此字符串作为控制器的响应发送时,它会以完整的转义字符返回给客户端。
这是我用来返回字符串的控制器的代码:
public class MyController : BaseController
{
[HttpPost]
public virtual HttpResponseMessage Post()
{
string myString = "{color: \"red\", value: \"2\"}";
HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.OK, myString, "application/json");
return response;
}
}
我的问题是:如何在客户端不显示转义字符的情况下将字符串“myString”返回给客户端?
谢谢!
【问题讨论】:
-
它们不应该出现在客户端,因为这些转义字符没有被编码到字符串中。它们应该由编译器简单地评估。
-
在这里找到了您问题的答案:stackoverflow.com/questions/17097841/…
标签: c# .net json asp.net-web-api