C#使用JSON从twitch api获取最新追随者的数据
我正在尝试制作一个应用程序,从“”获取最新的关注者,并将其保存到.txt文件中。我知道如何将字符串“display_name”保存到txt文件中,但我不知道如何获取该数据(display_name)。我在VisualStudio上安装了JSON.NET,并在网上搜索答案,但运气不佳。有人能帮我一下吗。定义以下类,这些类是根据发布JSON的结果改编的,使用C#使用JSON从twitch api获取最新追随者的数据,c#,json,visual-studio,json.net,twitch,C#,Json,Visual Studio,Json.net,Twitch,我正在尝试制作一个应用程序,从“”获取最新的关注者,并将其保存到.txt文件中。我知道如何将字符串“display_name”保存到txt文件中,但我不知道如何获取该数据(display_name)。我在VisualStudio上安装了JSON.NET,并在网上搜索答案,但运气不佳。有人能帮我一下吗。定义以下类,这些类是根据发布JSON的结果改编的,使用字典作为\u链接属性,使用日期时间作为日期: public class User { public long _id { get; se
字典作为\u链接属性,使用日期时间作为日期:
public class User
{
public long _id { get; set; }
public string name { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
public Dictionary<string, string> _links { get; set; }
public string display_name { get; set; }
public object logo { get; set; }
public object bio { get; set; }
public string type { get; set; }
}
public class Follow
{
public DateTime created_at { get; set; }
public Dictionary<string, string> _links { get; set; }
public bool notifications { get; set; }
public User user { get; set; }
}
public class RootObject
{
public RootObject()
{
this.follows = new List<Follow>();
}
public List<Follow> follows { get; set; }
public int _total { get; set; }
public Dictionary<string, string> _links { get; set; }
}
要按照在日期创建的对所有追随者进行反向排序,请执行以下操作:
var sortedFollowers = root.follows.OrderByDescending(f => f.created_at).ToList();
互联网上到处都是教程。例如,在Google.Ok中搜索JSON.NET教程时,我设法将数据转换为字符串DownloadData,现在获取“display_name”的最佳方法是什么“:”。代码如下:WebClient=newWebClient();String DownloadData=client.DownloadString(“);
var latestFollow = root.follows.Aggregate((Follow)null, (f1, f2) => (f1 == null || f2 == null ? f1 ?? f2 : f2.created_at > f1.created_at ? f2 : f1));
var latestName = latestFollow.user.display_name;
var sortedFollowers = root.follows.OrderByDescending(f => f.created_at).ToList();