【发布时间】:2018-12-10 09:32:15
【问题描述】:
我有以下 C# WebClient 返回的 JSON:
"\n\n\n{\n \"resultCount\":1,\n \"results\": [\n{\"wrapperType\":\"artist\", \"artistType\":\"Artist\", \"artistName\":\"Jack Johnson\", \"artistLinkUrl\":\"http://itunes.apple.com/us/artist/jack-johnson/id909253?uo=4\", \"artistId\":909253, \"amgArtistId\":468749, \"primaryGenreName\":\"Rock\", \"primaryGenreId\":21}]\n}\n\n\n"
或者,更清楚地说:
{
"resultCount ":1,
"results ":[
{
"wrapperType ":"artist ",
"artistType ":"Artist ",
"artistName ":"Jack Johnson ",
"artistLinkUrl ":"http://itunes.apple.com/us/artist/jack-johnson/id909253?uo=4 ",
"artistId ":909253,
"amgArtistId ":468749,
"primaryGenreName ":"Rock ",
"primaryGenreId ":21
}
]
}
我尝试将其反序列化为一个类,如下所示:
thejsonresult = JsonConvert.DeserializeObject<JsonResult>(WebRequest.Json);
但收到以下错误:
读取字符串时出错。意外标记:StartObject。第 7 行,位置 2。
我很迷茫,找不到任何关于此的文档。有人知道吗?
【问题讨论】:
-
该 JSON 字符串开头/结尾处的
"使其无效。删除这些,你就得到了一个有效的 JSON 字符串。 -
"只是因为它是 C# 中的字符串,它不是原始 JSON 的一部分 -
好吧,没有 " 它在 jsonlint.org 上解析得很好。所以......很奇怪。