码迷,mamicode.com
首页 > Windows程序 > 详细

C# 去掉webapi返回json所带的转义字符

时间:2019-04-25 18:47:40      阅读:846      评论:0      收藏:0      [点我收藏+]

标签:str   osi   cat   lap   encoding   数据   enc   tin   技术   

  

技术图片
反序列换报错:
{"Error converting value \"{\"Result\":true,\"Code\":\"\",\"Msg\":\"success\",\"Data\":[\"/_temp/Other/png/20190425/20190425173934_7723.png\"]}\" to type ‘Abhs.Code.HttpResponseResult‘. Path ‘‘, line 1, position 118."}
数据:
"{\"Result\":true,\"Code\":\"\",\"Msg\":\"success\",\"Data\":[\"/_temp/Other/png/20190425/20190425181452_6968.png\"]}"
解决办法:用HttpResponseMessage返回json会去掉转义字符

            string json = JsonConvert.SerializeObject(result);
            return new HttpResponseMessage { Content = new StringContent(json, Encoding.GetEncoding("UTF-8"), "application/json") };
返回结果:
{"Result":true,"Code":"","Msg":"success","Data":["/_temp/Other/png/20190425/20190425181452_6968.png"]}
View Code

 

C# 去掉webapi返回json所带的转义字符

标签:str   osi   cat   lap   encoding   数据   enc   tin   技术   

原文地址:https://www.cnblogs.com/hofmann/p/10770230.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!