2015-12-22 155 views
1

我在這裏確實沒有任何東西。通過各種有關C#和JSON的問題來看。我嘗試過插手,我只能或者A:獲取所有JSON輸出,或者什麼也沒有,我似乎無法弄清楚如何得到我想要的東西。JSON解析C#(數組?)

所以我從這裏拉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

你或許可以把完整的數據,並使用這個類

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

,然後你可以拉u想的任何數據desearlize它。

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