GoCardless Event Wont Deserialise

I am trying to implement the new GoCardless API, but I am having problems working with webcams.

I read the line answer by doing:

Stream req = Request.InputStream;
req.Seek(0, System.IO.SeekOrigin.Begin);

string requestContent = new StreamReader(req).ReadToEnd();

      

This gives me a json response like this:

"{\"events\":[{\"id\":\"EV000SDG4B5WRP\",\"created_at\":\"2017-07-31T08:17:16.202Z\",\"resource_type\":\"mandates\",\"action\":\"cancelled\",\"links\":{\"mandate\":\"MD0002010AE1MV\"},\"details\":{\"origin\":\"api\",\"cause\":\"bank_account_closed\",\"description\":\"The customer account was disabled at your request.\"},\"metadata\":{}}]}"

      

As per the docs, I would have to do

JsonConvert.DeserializeObject<GoCardless.Resources.Event>(requestContent);

      

However, this always gives me an empty object with all properties set to null.

The source code for the Event class can be found here: https://github.com/gocardless/gocardless-dotnet/blob/master/GoCardless/Resources/Event.cs

Why doesn't it deserialize the object?

+3


source to share


1 answer


Pretty sure JSON is an array of events. So first you need a root object:

public class Root
{
    public List<GoCardless.Resources.Event> Events { get; set; }
}

      



Now deserialize to this type:

var events = JsonConvert.DeserializeObject<Root>(requestContent);

      

+4


source







All Articles