예제 #1
0
        private void readArchiveJson() /* 读取json汇总的json */
        {
            MyWebClient webClient = new MyWebClient();
            string url = "http://bgmlist.com/json/archive.json";
            bool local = System.IO.File.Exists(archive);
            try
            {
                if (local)
                {
                    readLocalArchiveJson();
                    var maxMonth = Int32.Parse(archiveList.OrderByDescending(item => item.year).First().months.OrderByDescending(item => item.month).First().month);
                    var maxYear = Int32.Parse(archiveList.OrderByDescending(item => item.year).First().year);
                    if (year > maxYear)
                    {
                        local = false;
                    }
                    else
                    {
                        if (maxMonth + 3 <= month)
                        {
                            local = false;
                        }
                    }
                }

                if (local)
                {
                    readLocalArchiveJson();
                }
                else
                {
                    archiveList=new List<I.archive>();
                    byte[] b = webClient.DownloadData(url);
                    string jsonText = Encoding.UTF8.GetString(b, 0, b.Length);
                    Newtonsoft.Json.Linq.JObject aaaa = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(jsonText);
                    Newtonsoft.Json.Linq.JObject bb = (Newtonsoft.Json.Linq.JObject)aaaa.GetValue("data");
                    foreach (var item in bb)
                    {
                        archive asd=new archive();
                        asd.year=item.Key;
                        asd.months=new List<months>();
                        Newtonsoft.Json.Linq.JObject cc = (Newtonsoft.Json.Linq.JObject)item.Value;
                        foreach (var item1 in cc)
                        {
                            months m=new months();
                            m.month = item1.Key;
                            m.json = ((Newtonsoft.Json.Linq.JObject)item1.Value).GetValue("path").ToString();
                            asd.months.Add(m);
                        }
                        archiveList.Add(asd);
                    }
                    jsonText = JsonConvert.SerializeObject(archiveList);
                    //archiveList = JsonConvert.DeserializeObject<List<archive>>(jsonText);
                    System.IO.File.WriteAllText(archive, jsonText);
                }
            }
            catch (Exception ex)
            {
                if (System.IO.File.Exists(archive))
                {
                    readLocalArchiveJson();
                }
                if (archiveList == null || archiveList.Count < 1)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #2
0
        private void readArchiveJson()//读取json汇总的json
        {
            /**
            if (System.IO.File.Exists(archive))
            {
                readLocalArchiveJson();
            }
            else
            {
                MyWebClient webClient = new MyWebClient();
                string url = "http://bgmlist.com/json/archive.json";
                byte[] b = webClient.DownloadData(url);
                string jsonText = Encoding.UTF8.GetString(b, 0, b.Length);
                archiveList = JsonConvert.DeserializeObject<List<archive>>(jsonText);
                System.IO.File.WriteAllText(archive, jsonText);
            }
             * */
            /*
            MyWebClient webClient = new MyWebClient();
            string url = "http://bgmlist.com/json/archive.json";
            byte[] b = webClient.DownloadData(url);
            string jsonText = Encoding.UTF8.GetString(b, 0, b.Length);
            archiveList = JsonConvert.DeserializeObject<List<archive>>(jsonText);
            System.IO.File.WriteAllText(archive, jsonText);
             * */

            MyWebClient webClient = new MyWebClient();
            string url = "http://bgmlist.com/json/archive.json";
            archiveList = new List<I.archive>();
            byte[] b = webClient.DownloadData(url);
            string jsonText = Encoding.UTF8.GetString(b, 0, b.Length);
            Newtonsoft.Json.Linq.JObject aaaa = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(jsonText);
            Newtonsoft.Json.Linq.JObject bb = (Newtonsoft.Json.Linq.JObject)aaaa.GetValue("data");
            foreach (var item in bb)
            {
                archive asd = new archive();
                asd.year = item.Key;
                asd.months = new List<months>();
                Newtonsoft.Json.Linq.JObject cc = (Newtonsoft.Json.Linq.JObject)item.Value;
                foreach (var item1 in cc)
                {
                    months m = new months();
                    m.month = item1.Key;
                    m.json = ((Newtonsoft.Json.Linq.JObject)item1.Value).GetValue("path").ToString();
                    asd.months.Add(m);
                }
                archiveList.Add(asd);
            }
            jsonText = JsonConvert.SerializeObject(archiveList);
            //archiveList = JsonConvert.DeserializeObject<List<archive>>(jsonText);
            System.IO.File.WriteAllText(archive, jsonText);
        }