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"]}
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM