我想顯示從列表框中的eztv.re API中拉出的列表。我已經 嘗試使用:如何從c#中的json文件獲取列表?
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage response = await client.GetAsync(("http://eztvapi.re/shows/1&query_term=" + SearchTextBox.Text)))
{
using (Stream stream = response.Content.ReadAsStreamAsync().Result)
{
using (StreamReader reader = new StreamReader(stream))
{
string json = reader.ReadToEnd();
var root = JsonConvert.DeserializeObject<RootObject>(json);
var articles = root.Select(m => new Article { Name = root.title, ImagePath = root.images.poster, id = root._id, Year = root.year }).ToList();
foreach (Article s in articles)
{
this.Listbox.Items.Add(new Article { Name = s.Name, ImagePath = s.ImagePath, Year = s.Year, id = s.id });
}
}
}
}
但root.select不工作,我RootObject class是:
public class RootObject
{
public string _id { get; set; }
public Images images { get; set; }
public string imdb_id { get; set; }
public object last_updated { get; set; }
public int num_seasons { get; set; }
public string slug { get; set; }
public string title { get; set; }
public string tvdb_id { get; set; }
public string year { get; set; }
}
Article類是單純的字符串列表。與其他API(yts.to)我的代碼功能完美,但是在那一個,我用RootObject.Data,含
public List<Movie> movies { get; set; }
我知道,要解決這個可能是相當簡單的數據類,但我可以」似乎找不到它。
...並且錯誤是... –
看看DataContractJsonSerializer。 https://msdn.microsoft.com/en-us/library/bb410770(v=vs.110).aspx – noMad17