gpt4 book ai didi

c# - 使用 Json.net 反序列化时为 "Unexpected token: StartObject"

转载 作者:行者123 更新时间:2023-11-30 13:32:54 26 4
gpt4 key购买 nike

我有以下 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);

但收到以下错误:

Error reading string. Unexpected token: StartObject. Line 7, position 2.

我很迷茫,找不到任何相关文档。有人知道吗?

最佳答案

我相信问题实际上出在您尝试反序列化的类中。

您拥有的包装器属性未正确反序列化。如果它是您类(class)中的一个对象,那么它应该可以工作,但如果它是一个字符串(我猜是这样),那么 Json 反序列化器将尝试反序列化它并发现它不是字符串。

关于c# - 使用 Json.net 反序列化时为 "Unexpected token: StartObject",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10505306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com