I'm playing around with the Imgur API and having trouble deseralizing the JSON response. My JSON looks like this:
{
"data":{
"id":"zPBszkd",
"title":null,
"description":null,
"datetime":1634033771,
"type":"image\/png",
"animated":false,
"width":391,
"height":149,
"size":11093,
"views":0,
"bandwidth":0,
"vote":null,
"favorite":false,
"nsfw":null,
"section":null,
"account_url":null,
"account_id":0,
"is_ad":false,
"in_most_viral":false,
"has_sound":false,
"tags":[
],
"ad_type":0,
"ad_url":"",
"edited":"0",
"in_gallery":false,
"deletehash":"EUqn23MqOTdDOov",
"name":"",
"link":"https:\/\/i.imgur.com\/zPBszkd.png"
},
"success":true,
"status":200
}
But I'm unsure how to deseralize this using Newtonsoft. I've read a couple of guides and questions but still keep running into the same error of:
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[System.String]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Would appreciate a code snippet that deseralizes this JSON correctly and an explanation of why it has to be done a certain way