Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Automatic Property Deserialization - Lists

I'm trying to use automatic deserialization in my MVC action like so:

public void CreateEntitlementEntity(EntitlementEntityModel model) {
     // stuff
}

And here's the class I want to deserialize:

public class EntitlementEntityModel {
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }

    public List<string> Domains { get; set; }

    public EntitlementEntityModel() { }
}

I'm passing a JSON object of data to the controller action:

data: {
    FirstName: 'first',
    LastName: 'last',
    Email: '[email protected]',
    Domains: ['a','b','c']
}

All of the properties deserialize correctly except the List of strings. I would like to turn a JSON array into a List, but it instead gives me a list with one string in it, the JSON array string.

Is there a way to accomplish this in .Net Framework 3.5?

Thanks

like image 257
Tbabs Avatar asked May 29 '26 16:05

Tbabs


1 Answers

Maybe you can use some input from this thread?

Deserializing json array into .net class

like image 76
Simen S Avatar answered Jun 01 '26 04:06

Simen S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!