C# 去掉webapi返回json所带的转义字符
Posted hofmann
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 去掉webapi返回json所带的转义字符相关的知识,希望对你有一定的参考价值。
反序列换报错: {"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"]}
以上是关于C# 去掉webapi返回json所带的转义字符的主要内容,如果未能解决你的问题,请参考以下文章