public static List <RichListItem> Parse(String jsonString)
        {
            List <RichListItem> list = new List <RichListItem>();

            if (jsonString != null && !"".Equals(jsonString))
            {
                try
                {
                    JObject jsonObj = JObject.Parse(jsonString);
                    if (jsonObj != null && jsonObj.HasValues)
                    {
                        RichListItem newItem = new RichListItem();

                        String forecast = "", avgRain = "", temperature = "", avgTemperature = "";
                        JToken result = jsonObj["result"];
                        newItem.AvgRain        = avgRain = result["avgRain"].ToString();
                        newItem.Description    = forecast = result["forecast"].ToString();
                        newItem.Temperature    = temperature = result["temperature"].ToString();
                        newItem.AvgTemperature = avgTemperature = result["avgTemperature"].ToString();
                        newItem.ItemType       = WeatherItemType.WI_TYPE_NON;
                        newItem.ItemTemplate   = WeatherItemTemplate.WI_TEMPLATE_GLOBAL;

                        list.Add(newItem);
                    }
                }
                catch (Exception)
                {
                    list = new List <RichListItem>();
                }
            }

            return(list);
        }
        public static List <RichListItem> Parse(String jsonString)
        {
            List <RichListItem> list = new List <RichListItem>();

            if (jsonString != null && !"".Equals(jsonString))
            {
                try
                {
                    JObject jsonObj = JObject.Parse(jsonString);
                    if (jsonObj != null && jsonObj.HasValues)
                    {
                        JToken       result  = jsonObj["result"];
                        RichListItem newItem = new RichListItem();

                        newItem.Description  = result["description"].ToString();
                        newItem.StartTime    = result["validBeginTime"].ToString();
                        newItem.EndTime      = result["validEndTime"].ToString();
                        newItem.Wave         = result["wave"].ToString();
                        newItem.WaveLevel    = result["waveLevel"].ToString();
                        newItem.WindScale    = result["windScale"].ToString();
                        newItem.Wind         = result["wind"].ToString();
                        newItem.ItemType     = WeatherItemType.WI_TYPE_NON;
                        newItem.ItemTemplate = WeatherItemTemplate.WI_TEMPLATE_NEARSEA;

                        list.Add(newItem);
                    }
                }
                catch (Exception)
                {
                    list = new List <RichListItem>();
                }
            }

            return(list);
        }
        //{
        //  "result": {
        //    "description": "X",
        //    "gustWindScale": "-",
        //    "rain": "0.0",
        //    "id": "46692",
        //    "locationName": "台北",
        //    "time": "2012-03-08 00:15:00",
        //    "windDirection": "靜風",
        //    "windScale": "0",
        //    "temperature": 16.0
        //  }
        //}

        public static List <RichListItem> Parse(String jsonString)
        {
            List <RichListItem> list = new List <RichListItem>();

            if (jsonString != null && !"".Equals(jsonString))
            {
                try
                {
                    JObject jsonObj = JObject.Parse(jsonString);
                    if (jsonObj != null && jsonObj.HasValues)
                    {
                        String description = "", gustWindScale = "",
                               rain = "", id = "", locationName = "", time = "",
                               windDirection = "", windScale = "", temperature = "";

                        JToken result = jsonObj["result"];
                        description   = result["description"].ToString();
                        gustWindScale = result["gustWindScale"].ToString();
                        rain          = result["rain"].ToString();
                        id            = result["id"].ToString();
                        locationName  = result["locationName"].ToString();
                        time          = result["time"].ToString();
                        windDirection = result["windDirection"].ToString();
                        windScale     = result["windScale"].ToString();
                        temperature   = result["temperature"].ToString();

                        RichListItem itemOBS = new RichListItem();
                        itemOBS.Description   = description;
                        itemOBS.GustWindScale = gustWindScale;
                        itemOBS.RainScale     = rain;
                        itemOBS.Area          = locationName;
                        itemOBS.StartTime     = time;
                        itemOBS.WindDirection = windDirection;
                        itemOBS.WindScale     = windScale;
                        itemOBS.Temperature   = temperature;
                        itemOBS.ItemType      = WeatherItemType.WI_TYPE_NON;
                        itemOBS.ItemTemplate  = WeatherItemTemplate.WI_TEMPLATE_OBS;

                        list.Add(itemOBS);
                    }
                }
                catch (Exception)
                {
                    list = new List <RichListItem>();
                }
            }

            return(list);
        }
        public static List <RichListItem> Parse(String jsonString)
        {
            List <RichListItem> list = new List <RichListItem>();

            if (jsonString != null && !"".Equals(jsonString))
            {
                try
                {
                    JObject jsonObj = JObject.Parse(jsonString);
                    if (jsonObj != null && jsonObj.HasValues)
                    {
                        JToken result = jsonObj["result"];
                        JToken items  = result["items"];
                        if (items != null && items.HasValues)
                        {
                            JToken item = items.First;
                            while (item != null && item.HasValues)
                            {
                                RichListItem newItem = new RichListItem();
                                newItem.StartTime    = item["date"].ToString();        // 2012-03-10
                                newItem.Wave         = item["wave"].ToString();        // 小浪轉大浪
                                newItem.Description  = item["description"].ToString(); // 陰時多雲局部雨
                                newItem.Wind         = item["wind"].ToString();        // 偏北風
                                newItem.WindScale    = item["windScale"].ToString();   // 4至5陣風7級轉5至6陣風8級
                                newItem.ItemType     = WeatherItemType.WI_TYPE_NON;
                                newItem.ItemTemplate = WeatherItemTemplate.WI_TEMPLATE_SEA;
                                list.Add(newItem);
                                item = item.Next;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    list = new List <RichListItem>();
                }
            }

            return(list);
        }
Beispiel #5
0
        public static List <RichListItem> Parse(String jsonString)
        {
            List <RichListItem> list = new List <RichListItem>();

            if (jsonString != null && !"".Equals(jsonString))
            {
                try
                {
                    JObject jsonObj = JObject.Parse(jsonString);
                    if (jsonObj != null && jsonObj.HasValues)
                    {
                        String description = "";
                        JToken result      = jsonObj["result"];
                        JToken items       = result["items"];
                        if (items != null && items.HasValues)
                        {
                            JToken item = items.First;
                            while (item != null && item.HasValues)
                            {
                                // 正常來說這裡要跑三次,分別是三個 date
                                RichListItem newItem = new RichListItem();

                                newItem.StartTime = item["date"].ToString();
                                newItem.LunarDate = item["lunarDate"].ToString();

                                #region Tide Detail
                                JToken tides = item["tides"];
                                if (tides != null && tides.HasValues)
                                {
                                    JToken tide = tides.First;
                                    String shortTime = "", name = "", height = "";
                                    while (tide != null && tide.HasValues)
                                    {
                                        // 這裡是列出一天當中滿潮、乾潮的時間,數量不一定
                                        shortTime    = tide["shortTime"].ToString();
                                        name         = tide["name"].ToString();
                                        height       = tide["height"].ToString();
                                        description += String.Format("{0}\t\t\t{1}\t\t\t{2}cm\n", name, shortTime, height.PadLeft(6));
                                        tide         = tide.Next;
                                    }
                                    //description = description.TrimEnd('\n');
                                }
                                #endregion

                                newItem.Description  = description;
                                newItem.ItemType     = WeatherItemType.WI_TYPE_NON;
                                newItem.ItemTemplate = WeatherItemTemplate.WI_TEMPLATE_TIDE;

                                list.Add(newItem);
                                item = item.Next;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    list = new List <RichListItem>();
                }
            }

            return(list);
        }