【发布时间】:2021-10-15 16:41:46
【问题描述】:
我想返回这个 json 响应
{
"Type": "testing",
"Errors": {
"InputOne": [
"The input one is accepted"
],
"InputTwo": [
"The input two is accepted"
]
}
}
但在尝试了几轮之后,我得到的只是这个
{
"Type": "testing",
"Errors": {
"InputOne": "The input one is accepted",
"InputTwo": "The input two is accepted"
}
}
我可以知道我在这里缺少什么吗?
这些是我的代码
public string Type { get; set; }
public ErrorClass Errors { get; set; }
public class ErrorClass
{
public object InputOne { get; set; }
public object InputTwo { get; set; }
}
提前致谢!
【问题讨论】:
-
我猜它们都是字符串,而不是字符串的数组/列表/集合!
-
你需要一个 ErrorClass 中的数组/列表,比如 public List
-
你可以直接从 demo json -f.e. 创建类。 codewithoutcomplaint.com/… - 无需“尝试几轮”或how-to-auto-generate-a-c-sharp-class-file-from-a-json-string
-
@PatrickArtner 感谢您建议查看从 json 自动生成 c 尖锐文件!很有帮助!
标签: c# asp.net json asp.net-mvc asp.net-core