I have an issue to find the type of an object. I'm using MailChimp API and tried a couple of different scenarios. One of them is to send an incorrect email address (blablagmail.com, @ is missing).
I want to deserialize the json to be able to create a string with all the errors. Here the json with only the two properties that bug me:
"error_count":1,
"errors":[
{
"email_address":"blablagmail.com",
"error":"Please provide a valid email address."
}
],
Basically, what I try to do is to is to create an unique string with all the erros for my logger. Something like:
errors = "email_address:blablagmail.com, error:Please provide a valid email address."
I tried to cast errors
as List<Dictionary<string, string>>
but it doesn't work. The thing is the properties (email_address
or error
) can have a different name depending on the error.
Here the class I've created to deserialize the json
public class MailChimpResponse
{
public object[] new_members { get; set; }
public object[] updated_members { get; set; }
public object[] errors { get; set; }
public int total_created { get; set; }
public int total_updated { get; set; }
public int error_count { get; set; }
}
MailChimpResponse obj = new JavaScriptSerializer().Deserialize<MailChimpResponse>(response);
Now if error_count > 0 I want to log the errors so I would like to create a genreic function to convert this array of object (object[] errors
) to a string.
Any ideas?