string input ="{\"page\":1,\"results\":[{\"adult\":false,\"backdrop_path\":\"/ mMblxwsvvJ9wu8CVXVVjX4MBuN2.jpg\",\"id\":957,\"original_title\":\"Spaceballs\",\"release_date\":\"1987-06-24\",\"poster_path\":\"/9lBOjli8TrJghuzAulVNJvTNJCS.jpg\",\"popularity\":3.25235847573851,\"title\":\"Spaceballs\",\"vote_average\":7.7,\"vote_count\":35},{\"adult\":false,\"backdrop_path\":null,\"id\":56297,\"original_title\":\"Spaceballs: The Documentary\",\"release_date\":\"2005-05-05\",\"poster_path\":\"/kPVdkoT49zP8RcruDP3AtquZ7WT.jpg\",\"popularity\":0.46,\"title\":\"Spaceballs: The Documentary\",\"vote_average\":6.0,\"vote_count\":1}],\"total_pages\":1,\"total_results\":2}";
dynamic d = JObject.Parse(input);
foreach (var item in d.results)
{
Console.WriteLine(item.original_title);
}
如果您有模型类,您可以执行以下操作
var op = JsonConvert.DeserializeObject<AllResults>(input);
foreach (var item in op.results)
{
Console.WriteLine(item.original_title);
}
public class Result
{
public bool adult { get; set; }
public string backdrop_path { get; set; }
public int id { get; set; }
public string original_title { get; set; }
public string __invalid_name__release_date { get; set; }
public string poster_path { get; set; }
public double popularity { get; set; }
public string title { get; set; }
public double vote_average { get; set; }
public int __invalid_name__vote_count { get; set; }
public string release_date { get; set; }
public int? vote_count { get; set; }
}
public class AllResults
{
public int page { get; set; }
public List<Result> results { get; set; }
public int total_pages { get; set; }
public int total_results { get; set; }
}
从http://json2csharp.com/生成的类