Exemplo n.º 1
0
        public void LoadPlace()
        {
            try
            {
                using (var webClient = new System.Net.WebClient())
                {
                    var json = webClient.DownloadString(this.get_place_api);

                    Dictionary <string, string>[] p    = JsonConvert.DeserializeObject <Dictionary <string, string>[]>(json);
                    Dictionary <string, string>   item = new Dictionary <string, string>();
                    DataSet1TableAdapters.tb_placeTableAdapter tb_place = new DataSet1TableAdapters.tb_placeTableAdapter();
                    tb_place.TruncateData();
                    foreach (Dictionary <string, string> pp in p)
                    {
                        System.Console.WriteLine(Convert.ToInt32(pp["id"]));
                        item.Add(pp["id"], pp["place_name"]);
                        try
                        {
                            int insert_id = (int)tb_place.InsertQuery(Convert.ToInt32(pp["id"]), pp["place_name"]);
                            Console.WriteLine("ID:" + insert_id);
                        }
                        catch (InvalidDataException de)
                        {
                            Console.WriteLine(de.Message);
                        }
                    }

                    dlPlace.DataSource    = new BindingSource(item, null);
                    dlPlace.DisplayMember = "Value";
                    dlPlace.ValueMember   = "Key";
                    DataTable dt = tb_place.GetData();

                    Console.WriteLine("Data Count:" + tb_place.CountAll());


                    // Now parse with JSON.Net
                }
            }
            catch (JsonException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }