public async Task LoadCountries() { string json; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.vk.com/method/database.getCountries?need_all=1&count=1000"); WebResponse response = await Task.Factory.FromAsync <WebResponse>(request.BeginGetResponse, request.EndGetResponse, null); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { json = await reader.ReadLineAsync(); } SimpleVKJSonParser parser = new SimpleVKJSonParser(json); Countries = parser.ParseToDictionary("cid", "title"); }
public async Task LoadCities(string country, string toFind) { string json; string id = Countries.FirstOrDefault(x => x.Value == country).Key; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.vk.com/method/database.getCities?country_id=" + id + "&need_all=1&count=1000&q=" + toFind); WebResponse response = await Task.Factory.FromAsync <WebResponse>(request.BeginGetResponse, request.EndGetResponse, null); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { json = await reader.ReadLineAsync(); } SimpleVKJSonParser parser = new SimpleVKJSonParser(json); Cities = parser.ParseToDictionary("cid", "title"); }