1 回答
TA贡献1909条经验 获得超7个赞
应使用 Newtonsoft 的泛型反序列化器方法反序列化此字符串。
尝试创建一个新类:
public partial class GameResponse
{
[JsonProperty("response")]
public Response Response { get; set; }
}
public partial class Response
{
[JsonProperty("game_count")]
public long GameCount { get; set; }
[JsonProperty("games")]
public Game[] Games { get; set; }
}
public partial class Game
{
[JsonProperty("appid")]
public long Appid { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("playtime_2weeks", NullValueHandling = NullValueHandling.Ignore)]
public long? Playtime2Weeks { get; set; }
[JsonProperty("playtime_forever")]
public long PlaytimeForever { get; set; }
[JsonProperty("img_icon_url")]
public string ImgIconUrl { get; set; }
[JsonProperty("img_logo_url")]
public string ImgLogoUrl { get; set; }
[JsonProperty("has_community_visible_stats")]
public bool HasCommunityVisibleStats { get; set; }
[JsonProperty("playtime_windows_forever")]
public long PlaytimeWindowsForever { get; set; }
[JsonProperty("playtime_mac_forever")]
public long PlaytimeMacForever { get; set; }
[JsonProperty("playtime_linux_forever")]
public long PlaytimeLinuxForever { get; set; }
}
然后使用:
var json = wc.DownloadString("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=D4718FA8ED43C531523CF79310BE52FE&steamid=76561198440001695&include_appinfo=1");
var results = JsonConvert.DeserializeObject<GameResponse>(json);
小提琴:https://dotnetfiddle.net/Nf2LdB
- 1 回答
- 0 关注
- 161 浏览
添加回答
举报