

反序列换报错: {"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"]}
本文介绍了一种常见的JSON反序列化错误及其解决方案,当从HttpResponseMessage中读取JSON数据时,由于转义字符的问题可能导致解析失败。文章提供了一个通过自定义返回方式来避免这一问题的方法,即使用JsonConvert.SerializeObject将数据转换为字符串,并通过HttpResponseMessage的StringContent返回。

8128

被折叠的 条评论
为什么被折叠?



