Json反序列化始终返回null

时间:2017-06-03 14:36:14

标签: c# json steam-web-api

EDIT已找到解决方案

我一直在尝试从Steam获取用户的个人资料数据并显示已接收的信息。 问题是,反序列化的JSON元素会返回" null"什么时候叫。 我一直试图找到一个小时的解决方案而且我无法让它工作

这是基础json

    {
    "response": {
        "players": [
            {
                "steamid": "76561198202418604",
                "communityvisibilitystate": 3,
                "profilestate": 1,
                "personaname": "longboi",
                "lastlogoff": 1496425906,
                "profileurl": "http://steamcommunity.com/id/itsnewe/",
                "avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/99/99fbd7814e9bb6009c87e4f4d0aab3bb2ce12196.jpg",
                "avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/99/99fbd7814e9bb6009c87e4f4d0aab3bb2ce12196_medium.jpg",
                "avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/99/99fbd7814e9bb6009c87e4f4d0aab3bb2ce12196_full.jpg",
                "personastate": 0,
                "realname": "heck",
                "primaryclanid": "103582791430300181",
                "timecreated": 1419603965,
                "personastateflags": 0,
                "loccountrycode": "FR",
                "locstatecode": "A5"
            }
        ]

    }

课程

public class Player
{
    public string Steamid { get; set; }
    public int Communityvisibilitystate { get; set; }
    public int Profilestate { get; set; }
    public string Personaname { get; set; }
    public int Lastlogoff { get; set; }
    public string Profileurl { get; set; }
    public string Avatar { get; set; }
    public string Avatarmedium { get; set; }
    public string Avatarfull { get; set; }
    public int Personastate { get; set; }
    public string Realname { get; set; }
    public string Primaryclanid { get; set; }
    public int Timecreated { get; set; }
    public int Personastateflags { get; set; }
    public string Loccountrycode { get; set; }
    public string Locstatecode { get; set; }
}

public class Response
{
    public List<Player> Players { get; set; }
}

public class RootObject
{
    public Response Response { get; set; }
}

调用反序列化元素的方法

WebRequest request = WebRequest.Create(
          $"http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={Configuration.SteamAPIkey}&steamids={user}");
        request.Credentials = CredentialCache.DefaultCredentials;
        WebResponse response = request.GetResponse();
        Console.WriteLine(((HttpWebResponse)response).StatusDescription);
        Stream dataStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(dataStream);
        string responseFromServer = reader.ReadToEnd();
        await ReplyAsync($"```json\n{responseFromServer}```");
        Response resjs = JsonConvert.DeserializeObject<Response>(responseFromServer);
        await ReplyAsync(resjs.Players);

但我被告知**内容参数不能null,我不知道我做错了什么

0 个答案:

没有答案