gpt4 book ai didi

C# 自动属性反序列化 - 列表

转载 作者:行者123 更新时间:2023-11-30 17:18:51 26 4
gpt4 key购买 nike

我正尝试在我的 MVC 操作中使用自动反序列化,如下所示:

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

这是我要反序列化的类:

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() { }
}

我将一个 JSON 数据对象传递给 Controller ​​操作:

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

除字符串列表外,所有属性都正确反序列化。我想将一个 JSON 数组转换为一个列表,但它却给了我一个包含一个字符串的列表,即 JSON 数组字符串。

有没有办法在 .Net Framework 3.5 中实现这一点?

谢谢

最佳答案

也许您可以使用来自该线程的一些输入?

Deserializing json array into .net class

关于C# 自动属性反序列化 - 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5346334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com