小编act*_*apz的帖子

在 Newtonsoft JSON.NET 架构中禁用空类型

我有一个 MVC 应用程序,它将我的模型序列化为 json 模式(使用 Newtonsoft json.net 模式)。问题是我的数组中的项目有 type ["string", "null"],但我需要的只是"string". 这是我班级的代码:

public class Form
{
    [Required()]
    public string[] someStrings { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是由 Json.net 架构制作的架构:

"someStrings": {
  "type": "array",
  "items": {
    "type": [
      "string",
      "null"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

虽然我期待这个:

"someStrings": {
  "type": "array",
  "items": {
    "type": "string"        
  }
}
Run Code Online (Sandbox Code Playgroud)

请帮我摆脱那个“空”。

.net c# json json.net jsonschema

6
推荐指数
1
解决办法
1179
查看次数

标签 统计

.net ×1

c# ×1

json ×1

json.net ×1

jsonschema ×1