예제 #1
0
        public List<District> GetDistricts(int CityId)
        {
            AvitoWebClient web = new AvitoWebClient(auth.CredsCont);
            web.Encoding = Encoding.UTF8;
            string json = "";
            try
            {
                json = web.DownloadString(String.Format(districtsUrl, CityId));
            }
            catch (Exception e)
            {
                throw new LocationLoadException();
            }
            JArray arr;
            try
            {
                arr = JArray.Parse(json);
            }
            catch (Exception e)
            {
                return null;
            }
            List<District> districts = new List<District>();
            foreach (JObject x in arr)
            {
                District d = new District();
                d.Id = Int32.Parse(x["id"].ToString());
                d.Name = x["name"].ToString();
                districts.Add(d);
            }

            return districts.Count == 0 ? null : districts;
        }