Esempio n. 1
0
        public List <Metro> GetMetros(int CityId)
        {
            AvitoWebClient web = new AvitoWebClient(auth.CredsCont);

            web.Encoding = Encoding.UTF8;
            string json = "";

            try
            {
                json = web.DownloadString(String.Format(metrosUrl, CityId));
            }
            catch (Exception e)
            {
                throw new LocationLoadException();
            }
            JArray arr;

            try
            {
                arr = JArray.Parse(json);
            }
            catch (Exception e)
            {
                return(null);
            }
            List <Metro> metros = new List <Metro>();

            foreach (JObject x in arr)
            {
                Metro m = new Metro();
                m.Id   = Int32.Parse(x["id"].ToString());
                m.Name = x["name"].ToString();
                metros.Add(m);
            }

            return(metros.Count == 0 ? null : metros);
        }
Esempio n. 2
0
        public List<Metro> GetMetros(int CityId)
        {
            AvitoWebClient web = new AvitoWebClient(auth.CredsCont);
            web.Encoding = Encoding.UTF8;
            string json = "";
            try
            {
                json = web.DownloadString(String.Format(metrosUrl, CityId));
            }
            catch (Exception e)
            {
                throw new LocationLoadException();
            }
            JArray arr;
            try
            {
                arr = JArray.Parse(json);
            }
            catch (Exception e)
            {
                return null;
            }
            List<Metro> metros = new List<Metro>();
            foreach (JObject x in arr)
            {
                Metro m = new Metro();
                m.Id = Int32.Parse(x["id"].ToString());
                m.Name = x["name"].ToString();
                metros.Add(m);
            }

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