This is my JSON file
{
"id": "5f5643b34ae3b73a74622a20",
"checkItemStates": [],
"closed": false,
"dateLastActivity": "2020-09-07T15:13:27.924Z",
"desc": "",
"descData": null,
"dueReminder": null,
"idBoard": "5f56231449e3e149cd81f345",
"idList": "5f554014d13fa38a52274132",
"idMembersVoted": [],
"idShort": 2,
"idAttachmentCover": null,
"idLabels": [],
"manualCoverAttachment": false,
"name": "Hello World",
"pos": 16384,
"shortLink": "aqz6ee6J",
"isTemplate": false,
"dueComplete": false,
"due": null,
"email": null,
"labels": [],
"shortUrl": "https://trello.com/c/aqz6ee6J",
"start": null,
"url": "https://trello.com/c/aqz6ee6J/2-hello-world",
"cover": {
"idAttachment": null,
"color": null,
"idUploadedBackground": null,
"size": "normal",
"brightness": "light"
},
"idMembers": [
"5b615a281019e549117835fd"
],
"idChecklists": [],
"badges": {
"attachmentsByType": {
"trello": {
"board": 0,
"card": 0
}
},
"location": false,
"votes": 0,
"viewingMemberVoted": false,
"subscribed": true,
"fogbugz": "",
"checkItems": 0,
"checkItemsChecked": 0,
"checkItemsEarliestDue": null,
"comments": 0,
"attachments": 0,
"description": false,
"due": null,
"dueComplete": false,
"start": null
},
"subscribed": true
}
this is my class
public class Card
{
public class CardDetails
{
public string Id { get; set; }
public string Name { get; set; }
public List<object> CheckItemStates { get; set; }
public bool Closed { get; set; }
public DateTime DateLastActivity { get; set; }
public string Desc { get; set; }
public object DescData { get; set; }
public object DueReminder { get; set; }
public string IdBoard { get; set; }
public string IdList { get; set; }
public List<object> IdMembersVoted { get; set; }
public int IdShort { get; set; }
public object IdAttachmentCover { get; set; }
public List<object> IdLabels { get; set; }
public bool ManualCoverAttachment { get; set; }
public int Oos { get; set; }
public string ShortLink { get; set; }
public bool IsTemplate { get; set; }
public bool DueComplete { get; set; }
public object Due { get; set; }
public object Email { get; set; }
public List<object> Labels { get; set; }
public string ShortUrl { get; set; }
public object Start { get; set; }
public string Url { get; set; }
public Cover Cover { get; set; }
public List<string> IdMembers { get; set; }
public List<object> IdChecklists { get; set; }
public Badges Badges { get; set; }
public bool Subscribed { get; set; }
}
public class Cover
{
public object IdAttachment { get; set; }
public object Color { get; set; }
public object IdUploadedBackground { get; set; }
public string Size { get; set; }
public string Brightness { get; set; }
}
public class Trello
{
public int Board { get; set; }
public int Card { get; set; }
}
public class AttachmentsByType
{
public Trello Trello { get; set; }
}
public class Badges
{
public AttachmentsByType AttachmentsByType { get; set; }
public bool Location { get; set; }
public int Votes { get; set; }
public bool ViewingMemberVoted { get; set; }
public bool Subscribed { get; set; }
public string Fogbugz { get; set; }
public int CheckItems { get; set; }
public int CheckItemsChecked { get; set; }
public object CheckItemsEarliestDue { get; set; }
public int Comments { get; set; }
public int Attachments { get; set; }
public bool Description { get; set; }
public object Due { get; set; }
public bool DueComplete { get; set; }
public object Start { get; set; }
}
}
the last but not least, this my request implementation
HttpClient httpClient = new HttpClient();
public async Task<List<Card>> GetApiData()
{
var uri = new Uri("https://api.trello.com/1/cards/.......");
HttpResponseMessage respone = await httpClient.GetAsync(uri);
respone.Headers.Add("Accept", "application/json");
var content = await respone.Content.ReadAsStringAsync();
var json = JsonConvert.DeserializeObject<List<Card>>(content);
return json;
}
I am always getting the following error no matter what:
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[LeanVoting.Trello.Card]' 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. Path 'id', line 1, position 6.
The steps I have already taken are:
- Remove attributes that I don't need (make it shorter)
- According to the error, I have also remove datatype like int, collection List<>, objects as well as boolean.
- Change them all to string
So, unfortunately, it's still not working and I can't figure out the reason anymore.
It would be a big pleaser if some could help me with.
Thanks in advance :)