Deserialize json string

Hi, I got some trouble with deserialize json string with class, I got this error :

" Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ‘JsonTest.EmailModels’ because the type requires a JSON object (e.g. {“name”:“value”}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {“name”:“value”}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array."

        static void Main(string[] args)
        string json = @"[


EmailModels emailModel = JsonConvert.DeserializeObject(json);
foreach (var item in

public class EmailModels
    public Insurance insurance { get; set; }

public class Insurance
    public InsIndividual individual { get; set; }
    public InsMulti multi { get; set; }

public class InsIndividual
    public string registrationID { get; set; }
    public string amount { get; set; }
    public string FullName { get; set; }
    public string Email { get; set; }
public class InsMulti
    public string borRegistrationID { get; set; }
    public string amount { get; set; }
    public Dictionary<string, string> paidFor { get; set; }
    public Dictionary<string, string> emailList { get; set; }

This kind of question is better asked at

You can use for that

There are many exemples :slight_smile:

You have a list of emails.

In that class you can add List<string> emails, I think.

Also this can help you

Good luck ! :slight_smile:

1 Like
.NET Foundation Website | Blog | Projects | Code of Conduct