返回json对象给IE8的兼容性问题

程序在用IE8浏览时会有兼容性问题。

1,返回json对象给IE8时,会把json对象下载下来。

2,IE8的编码格式跟其他浏览器不一样,导致中文显示成乱码。

解决办法:

1,设置返回的类型为text/html

2,转json字符串的时候,编码格式设置为 Encoding.Default

if (isIe8)
{
    response.Content = new StringContent(Purple.JsonHelper.Serializer(topResponse), 
              Encoding.Default); response.Content.Headers.ContentType
= new MediaTypeHeaderValue("text/html"); } else { response.Content = new StringContent(Purple.JsonHelper.Serializer(topResponse),
              Encoding.UTF8); response.Content.Headers.ContentType
= new MediaTypeHeaderValue("text/json"); }

IE8在前台用到的时候,用json2.js转一下:

var res = JSON.parse(data);

问题解决。

原文地址:https://www.cnblogs.com/uncleJOKER/p/4884592.html