Esempio n. 1
0
        public static WeatherIndex GetIndex(string area)
        {
            WeatherIndex i = new WeatherIndex();
            try
            {
                string json = GetJson(area, "index");
                if (!json.Equals(string.Empty) && !json.Contains("error data"))
                {
                    XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(json), XmlDictionaryReaderQuotas.Max);
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.Load(reader);
                    Log.WriteDebug(xdoc.InnerText);

                    #region 输出完整的XML,分析格式
                    //StringWriter stringWriter = new StringWriter();
                    //XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
                    //xmlTextWriter.Formatting = Formatting.Indented;
                    //foreach (XmlNode xmlNode in xdoc)
                    //{
                    //    xmlNode.WriteTo(xmlTextWriter);
                    //}

                    //Log.WriteLog(stringWriter.ToString());
                    #endregion

                    #region 用xml解析json,并为相关的成员变量赋值
                    try
                    {
                        ///获取到的属性信息
                        XmlNode clIndex = xdoc.FirstChild.SelectSingleNode("i").FirstChild;

                        i.cl = clIndex.SelectSingleNode("i1").InnerText;
                        i.clCN = clIndex.SelectSingleNode("i2").InnerText;
                        i.clCNAlias = clIndex.SelectSingleNode("i3").InnerText;
                        i.clLevel = clIndex.SelectSingleNode("i4").InnerText;
                        i.clDetails = clIndex.SelectSingleNode("i5").InnerText;

                        XmlNode coIndex = clIndex.NextSibling;
                        i.co = coIndex.SelectSingleNode("i1").InnerText;
                        i.coCN = coIndex.SelectSingleNode("i2").InnerText;
                        i.coCNAlias = coIndex.SelectSingleNode("i3").InnerText;
                        i.coLevel = coIndex.SelectSingleNode("i4").InnerText;
                        i.coDetails = coIndex.SelectSingleNode("i5").InnerText;


                        XmlNode ctIndex = coIndex.NextSibling;
                        i.ct = ctIndex.SelectSingleNode("i1").InnerText;
                        i.ctCN = ctIndex.SelectSingleNode("i2").InnerText;
                        i.ctCNAlias = ctIndex.SelectSingleNode("i3").InnerText;
                        i.ctLevel = ctIndex.SelectSingleNode("i4").InnerText;
                        i.ctDetails = ctIndex.SelectSingleNode("i5").InnerText;

                    }
                    catch (Exception ex)
                    {
                        Log.WriteError("GetIndex>>>>>" + ex.Message);
                    }
                    #endregion

                }
            }
            catch (Exception ex)
            {
                Log.WriteError("GetIndex错误>>>>>" + ex.Message);
            }
            return i;
        }
Esempio n. 2
0
        public static WeatherIndex GetIndex(string area)
        {
            WeatherIndex i = new WeatherIndex();

            try
            {
                string json = GetJson(area, "index");
                if (!json.Equals(string.Empty) && !json.Contains("error data"))
                {
                    XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(json), XmlDictionaryReaderQuotas.Max);
                    XmlDocument         xdoc   = new XmlDocument();
                    xdoc.Load(reader);
                    Log.WriteDebug(xdoc.InnerText);

                    #region 输出完整的XML,分析格式
                    //StringWriter stringWriter = new StringWriter();
                    //XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
                    //xmlTextWriter.Formatting = Formatting.Indented;
                    //foreach (XmlNode xmlNode in xdoc)
                    //{
                    //    xmlNode.WriteTo(xmlTextWriter);
                    //}

                    //Log.WriteLog(stringWriter.ToString());
                    #endregion

                    #region 用xml解析json,并为相关的成员变量赋值
                    try
                    {
                        ///获取到的属性信息
                        XmlNode clIndex = xdoc.FirstChild.SelectSingleNode("i").FirstChild;

                        i.cl        = clIndex.SelectSingleNode("i1").InnerText;
                        i.clCN      = clIndex.SelectSingleNode("i2").InnerText;
                        i.clCNAlias = clIndex.SelectSingleNode("i3").InnerText;
                        i.clLevel   = clIndex.SelectSingleNode("i4").InnerText;
                        i.clDetails = clIndex.SelectSingleNode("i5").InnerText;

                        XmlNode coIndex = clIndex.NextSibling;
                        i.co        = coIndex.SelectSingleNode("i1").InnerText;
                        i.coCN      = coIndex.SelectSingleNode("i2").InnerText;
                        i.coCNAlias = coIndex.SelectSingleNode("i3").InnerText;
                        i.coLevel   = coIndex.SelectSingleNode("i4").InnerText;
                        i.coDetails = coIndex.SelectSingleNode("i5").InnerText;


                        XmlNode ctIndex = coIndex.NextSibling;
                        i.ct        = ctIndex.SelectSingleNode("i1").InnerText;
                        i.ctCN      = ctIndex.SelectSingleNode("i2").InnerText;
                        i.ctCNAlias = ctIndex.SelectSingleNode("i3").InnerText;
                        i.ctLevel   = ctIndex.SelectSingleNode("i4").InnerText;
                        i.ctDetails = ctIndex.SelectSingleNode("i5").InnerText;
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError("GetIndex>>>>>" + ex.Message);
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Log.WriteError("GetIndex错误>>>>>" + ex.Message);
            }
            return(i);
        }