0

我不能使用 Youtube API,因为 WP 不支持它们,所以我选择只使用 JSON 响应。好像 Youtube 已经将响应类型更改为 JSON-C,我该如何解析这个?

https://www.googleapis.com/youtube/v3/search?part=snippet&order=relevance&q=lil+b&key=AIzaSyACjwJrIBICZxPb1x3JRq-FQ8iaei7LqXA&alt=json

我试过 Newtonsoft JSON 但它也不支持它,有什么建议吗?谢谢!

4

1 回答 1

0

你可以试试下面的代码。我已将 json 数据保存为文本文件。使用 jsonCsharp 您可以生成模型类。http://json2csharp.com/

var json = System.IO.File.ReadAllText(@"C:\json.txt"); //get json data
var result = JsonConvert.DeserializeObject<RootObject>(json);

public class PageInfo
{
    public int totalResults { get; set; }
    public int resultsPerPage { get; set; }
}

public class Id
{
    public string kind { get; set; }
    public string channelId { get; set; }
    public string videoId { get; set; }
}

public class Default
{
    public string url { get; set; }
}

public class Medium
{
    public string url { get; set; }
}

public class High
{
    public string url { get; set; }
}

public class Thumbnails
{
    public Default @default { get; set; }
    public Medium medium { get; set; }
    public High high { get; set; }
}

public class Snippet
{
    public string publishedAt { get; set; }
    public string channelId { get; set; }
    public string title { get; set; }
    public string description { get; set; }
    public Thumbnails thumbnails { get; set; }
    public string channelTitle { get; set; }
}

public class Item
{
    public string kind { get; set; }
    public string etag { get; set; }
    public Id id { get; set; }
    public Snippet snippet { get; set; }
}

public class RootObject
{
    public string kind { get; set; }
    public string etag { get; set; }
    public PageInfo pageInfo { get; set; }
    public string nextPageToken { get; set; }
    public List<Item> items { get; set; }
}
于 2013-07-01T04:52:00.547 回答