LifeAct
@LifeAct
Создаем и раскручиваем, не ставим на конвейер

Как спарсить json из файла?

Всем привет! Ребят помогите разобраться в проблеме, несколько часов уже бьюсь, вот что есть:

internal static class Serializer
    {     

        internal static T Deserialize<T>(string fileName)
        {
            string json = System.IO.File.ReadAllText(fileName);
            T res = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json);
            return res;
        }
    }


    public class Features
    {
        public int satellite { get; set; }
        public int webcams { get; set; }
        public int forecast { get; set; }
    }

    public class Response
    {
        public string version { get; set; }
        public string termsofService { get; set; }
        public Features features { get; set; }
    }

    public class Satellite
    {
        public string image_url { get; set; }
        public string image_url_ir4 { get; set; }
        public string image_url_vis { get; set; }
    }

    public class Forecastday
    {
        public int period { get; set; }
        public string icon { get; set; }
        public string icon_url { get; set; }
        public string title { get; set; }
        public string fcttext { get; set; }
        public string fcttext_metric { get; set; }
        public string pop { get; set; }
    }

    public class TxtForecast
    {
        public string date { get; set; }
        public List<Forecastday> forecastday { get; set; }
    }


//вызов
  string pathToFIle = @"d:\t.txt";
            TxtForecast response = Serializer.Deserialize<TxtForecast>(pathToFIle);
            String[] titles = response.forecastday.Select(item => item.title).ToArray(); // Массив названий
            String[] urls = response.forecastday.Select(item => item.fcttext_metric).ToArray(); // Массив адресов


мой файл с джейсоном https://yadi.sk/i/dAZeCk8e35wViv

мне нужно получить значения погоды на 5 дней - joxi.ru/QY2LqkJiPlJGA6

как не пытаюсь, вот тут T res = Newtonsoft.Json.JsonConvert.DeserializeObject(json); всегда значение null, хотя тут есть string json = System.IO.File.ReadAllText(fileName);
  • Вопрос задан
  • 624 просмотра
Пригласить эксперта
Ответы на вопрос 1
sgjurano
@sgjurano
Разработчик
На правах троллинга:
with open('filename.json') as f:
data = json.load(f)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы