2015-12-22 5 views
1

У меня действительно ничего нет. Просмотрели всевозможные вопросы, касающиеся C# и JSON. Я пробовал вмешаться, я могу только A: получить все выходные JSON или ничего, я не могу понять, как получить то, что я хочу.JSON Parsing C# (Array?)

Так что я тяну JSON отсюда: https://yts.ag/api/v2/list_movies.json?limit=1&quality=720p Я ограничил его только 1 ради того, чтобы быть легким на глазах здесь, вы можете увеличить его, чтобы увидеть, может ли код масштабироваться или нет.

Теперь, что я пытаюсь сделать, введите пару «ключ/значение» из URL-адреса и значение этого ключа.

+0

Кроме того, дубликат https://stackoverflow.com/questions/1207731/how-can-i-deserialize-json-to-a-simple-dictionarystring-string-in-asp-net?rq= 1 & https://stackoverflow.com/questions/2546138/deserializing-json-data-to-c-sharp-using-json-net?rq=1 и многие другие – Nikola

ответ

0

Вы, вероятно, может взять полные данные и desearlize его с помощью этой классы

public class Rootobject 
{ 
    public string status { get; set; } 
    public string status_message { get; set; } 
    public Data data { get; set; } 
    public Meta meta { get; set; } 
} 

public class Data 
{ 
    public int movie_count { get; set; } 
    public int limit { get; set; } 
    public int page_number { get; set; } 
    public Movie[] movies { get; set; } 
} 

public class Movie 
{ 
    public int id { get; set; } 
    public string url { get; set; } 
    public string imdb_code { get; set; } 
    public string title { get; set; } 
    public string title_english { get; set; } 
    public string title_long { get; set; } 
    public string slug { get; set; } 
    public int year { get; set; } 
    public float rating { get; set; } 
    public int runtime { get; set; } 
    public string[] genres { get; set; } 
    public string summary { get; set; } 
    public string description_full { get; set; } 
    public string synopsis { get; set; } 
    public string yt_trailer_code { get; set; } 
    public string language { get; set; } 
    public string mpa_rating { get; set; } 
    public string background_image { get; set; } 
    public string background_image_original { get; set; } 
    public string small_cover_image { get; set; } 
    public string medium_cover_image { get; set; } 
    public string large_cover_image { get; set; } 
    public string state { get; set; } 
    public Torrent[] torrents { get; set; } 
    public string date_uploaded { get; set; } 
    public int date_uploaded_unix { get; set; } 
} 

public class Torrent 
{ 
    public string url { get; set; } 
    public string hash { get; set; } 
    public string quality { get; set; } 
    public int seeds { get; set; } 
    public int peers { get; set; } 
    public string size { get; set; } 
    public int size_bytes { get; set; } 
    public string date_uploaded { get; set; } 
    public int date_uploaded_unix { get; set; } 
} 

public class Meta 
{ 
    public int server_time { get; set; } 
    public string server_timezone { get; set; } 
    public int api_version { get; set; } 
    public string execution_time { get; set; } 
} 

десериализации JSON как этот

Rootobject JsonObj = JsonConvert.DeserializeObject<Rootobject>(json); 

, а затем вы можете вытащить все данные, у хотел.

string movieURL = JsonObj.data.movies[0].url;