I am trying to parse a List of Comment objects from here. A comment object is a class in the leankit namespace: LeanKit.API.Client.Library.TransferObjects.Comment
but I get an error in the final line of the block below specifically over responseString
:
cannot convert from 'System.Collections.Generic.IList' to string
Why am I getting this? I am specifying a custom class I created specifically to deserialize the list:
public class MyCommentList
{
public string ReplyText { get; set; }
public List<Comment> ReplyData { get; set; }
public string ReplyCode { get; set; }
}
calling the class
var url = "https://" + acctName + ".leankit.com/kanban/api/card/getcomments/" + boardid + "/" + cardid;
var responseString = await url.WithBasicAuth("xxx", "yyy").GetJsonListAsync();
MyCommentList mycomment = JsonConvert.DeserializeObject<MyCommentList>(responseString);
a cleaner version of calling the class (using Flurl):
var url = "https://" + acctName + ".leankit.com/kanban/api/card/getcomments/" + boardid + "/" + cardid;
MyCommentList mycomment = await url.WithBasicAuth("xxx", "yyy").GetAsync().ReceiveJson<MyCommentList>();
The JSON structure (from the link above) reproduced here:
{
"ReplyData": [
[
{
"Id": 256487698,
"Text": "First comment for this card.",
"TaggedUsers": null,
"PostDate": "10/14/2015 at 04:36:02 PM",
"PostedByGravatarLink": "3ab1249be442027903e1180025340b3f",
"PostedById": 62984826,
"PostedByFullName": "David Neal",
"Editable": true
}
]
],
"ReplyCode": 200,
"ReplyText": "Card comments successfully retrieved."
}
> ReplyData { get; set; }` and it should work.
> ReplyData` works for me, see https://dotnetfiddle.net/w3Z8PT. Is this your `Comment` class? https://github.com/LeanKit/LeanKit.API.Client/blob/master/LeanKit.API.Client.Library/TransferObjects/Comment.cs
– dbc May 02 '18 at 21:44