从web api JSON C#中删除斜杠 [英] Removing slash from web api JSON C#

查看:178
本文介绍了从web api JSON C#中删除斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的字符串是:



  string  success =  ; 
success = {\status \:\无效的密钥\} ;
this .Context.Response.ContentType = application / json; charset = utf-8;
this .Context.Response.Write(serializer.Serialize(success));



i got输出为:



   {\status \:\无效密钥\} 





i想要输出喜欢:



 {  status 无效密钥} 





我尝试过的事情:



  string  success =  ; 
success = {\status \:\无效的密钥\} ;
this .Context.Response.ContentType = application / json; charset = utf-8;
this .Context.Response.Write(serializer.Serialize(success));

解决方案

斜杠不会出现在实际输出中,只有在嵌入具有特殊字符的字符串时才需要它们,例如在c#源文件中,这称为转义。



您也可以从代码中删除 serializer.Serialize(成功),然后发送成功

My string is :

string success = "";
success = "{\"status\": \"Invalid Key\"}";
this.Context.Response.ContentType = "application/json; charset=utf-8";
this.Context.Response.Write(serializer.Serialize(success));


i got output as:

"{\"status\": \"Invalid Key\"}"



i want output like:

{"status": "Invalid Key"}



What I have tried:

string success = "";
success = "{\"status\": \"Invalid Key\"}";
this.Context.Response.ContentType = "application/json; charset=utf-8";
this.Context.Response.Write(serializer.Serialize(success));

解决方案

The slash will not appear in the actual output, they are only needed when you are embedding strings with special characters like " in c# source files, this is called "escaping".

You can also remove the serializer.Serialize(success) from your code and just send the success.


这篇关于从web api JSON C#中删除斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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