"Unexpected token: StartObject" when Deserializing with Json.net

c#, json, json.net

Solution

This doesn't throw any exceptions for me in LINQPad:

JsonConvert.DeserializeObject<JsonResult>("\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")

If you're getting different results, you may want to try a different version of JSON.NET to see if it's a bug.

Problem

I have the following JSON that a C# WebClient returned: ``` "\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" ``` or, more clearly: ``` { "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 } ] } ``` I've tried deserializing this to a class, like so: ``` thejsonresult = JsonConvert.DeserializeObject<JsonResult>(WebRequest.Json); ``` but received the following error: Error reading string. Unexpected token: StartObject. Line 7, position 2. I'm pretty lost and can't find any documentation on this. Anyone got a clue?

Original source