1

I really have nothing here. Looked through all sorts of questions relating to C# and JSON. I have tried meddling, I can only either A: Get all the JSON output, or nothing, I can't seem to figure out how to get what I want.

So I am pulling JSON from here: https://yts.ag/api/v2/list_movies.json?limit=1&quality=720p I have only limited it to 1 for the sake of being easy on the eyes here, you can increase it to see if the code can scale or not.

Now, what I am trying to do is, key the Key/Value pair from URL and the Value of that key.

Johnathon
  • 33
  • 4
  • Also, duplicate of 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 and many more – Nikola Dec 22 '15 at 07:00

1 Answers1

0

You can probably take the complete data and desearlize it using this classes

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; }
}

Deserialize the JSON like this

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

and then You can pull whatever data u wanted.

string movieURL = JsonObj.data.movies[0].url;
Mohit S
  • 13,723
  • 6
  • 34
  • 69