【发布时间】:2021-09-15 08:29:42
【问题描述】:
控制器有什么方法可以返回空属性的json 模型或列表,但不为空
示例模型:
public class Model
{
public string name;
public string comment;
public List<Contact> Contacts;
}
public class Contact
{
public int id;
public string title;
}
static void Main(string[] args)
{
Model model1 = new Model()
{
name = "Max"
};
}
如果我们有一个空列表,那么我想得到这样一个json:
{
"name": "Max",
"comment": "",
"contacts": []
}
【问题讨论】:
标签: c# json asp.net-core