c# ASP.NET WebService Response.Write乱码解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32915337/article/details/85049407

输出json数据方式为:

Context.Response.Write(json);
Context.Response.End();

由于asmx文件输出为utf-8,但网站为gb2312,导致乱码

解决方法1:

修改web.config文件:

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="zh-CN" fileEncoding="utf-8" /> 

解决方法2:

通过 contentType: "application/json" 设置编码:

Context.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
Context.Response.ContentType = "application/json; charset=utf-8";
Context.Response.Write(json);            
Context.Response.End();

猜你喜欢

转载自blog.csdn.net/qq_32915337/article/details/85049407
今日推荐