【发布时间】:2016-02-24 06:44:16
【问题描述】:
我正在尝试使用 Steam 的 Web API 接收 JSON 并使用 JSON.Net 解析它。我只是硬编码一个我知道我会收到 JSON 的 URL。我运行它时遇到以下错误:
解析值时遇到意外字符:。路径'',行 0,位置 0。
错误指向我的控制器的第 22 行:
第 22 行:SteamResponse 响应 = JsonConvert.DeserializeObject(json);
这是我的课程:
public class Game
{
public int appid { get; set; }
public int playtime_forever { get; set; }
public int? playtime_2weeks { get; set; }
}
public class SteamResponse
{
public int game_count { get; set; }
public List<Game> games { get; set; }
}
public class RootObject
{
public SteamResponse response { get; set; }
}
我的控制器如下所示:
List<Game> gameList = new List<Game>();
WebClient wc = new WebClient();
var json = wc.DownloadString("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=" + steamAPIKey + "&steamid=76561197994394917&format=json");
SteamResponse response = JsonConvert.DeserializeObject<SteamResponse>(json);
我已经在浏览器中访问了该 URL 以验证它是否正确,并且我还使用 JSON Lint 测试了该 URL。我不确定我在这里做错了什么 - 我检查了其他主题并检查了他们列出的问题但没有找到它们。
【问题讨论】:
标签: json asp.net-mvc parsing json.net webclient