zoukankan      html  css  js  c++  java
  • C# 解析json数据出现---锘縖

    解析json数据的时候出现 - 锘縖,不知道是不是乱码,反正我是不认识这俩字。后来发现是json的 '[' 字符转换的

    网上搜了一下,说的是字符集不匹配,把字符集改为GB2312。

    一、贴下处理json数据的代码,这样处理过之后,就出现  锘縖,原本以为 Encoding.Default.GetString,默认的是GB2312,看来好像不是。

               string pageHtml = "";
                try
                {
                    WebClient MyWebClient = new WebClient();
                    MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
                    Byte[] pageData = MyWebClient.DownloadData(html); //从指定网站下载数据,url是下载数据的网址
                    pageHtml = Encoding.Default.GetString(pageData);  
                }
                catch (WebException webEx)
                {
                    Console.WriteLine(webEx.Message.ToString());
                }
                return pageHtml;

    二、解决办法:通过字节流读取,格式为GB2312就正常了。

           string pageHtml = "";
                try
                {
                    WebClient MyWebClient = new WebClient();
                    MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
                    Byte[] pageData = MyWebClient.DownloadData(html); //从指定网站下载数据
                    MemoryStream ms = new MemoryStream(pageData);
                    using (StreamReader sr = new StreamReader(ms, Encoding.GetEncoding("GB2312")))
                    {
                        pageHtml = sr.ReadLine();
                    }
                }
                catch (WebException webEx)
                {
                    Console.WriteLine(webEx.Message.ToString());
                }
                return pageHtml;
  • 相关阅读:
    Ubuntu: Set socks5 proxy for git
    Tornado实现一个消息墙。
    android 5.0开启google now 【需ROOT】
    python 回调函数
    php开发bug
    复习
    关于 xshell
    前端页面
    yii框架对数据库查询访问处理
    前端笔记
  • 原文地址:https://www.cnblogs.com/zhangjd/p/8135647.html
Copyright © 2011-2022 走看看