C# Newtonsoft JsonSchema.Parse失败
这是我的json模式文件C# Newtonsoft JsonSchema.Parse失败,c#,json,json.net,C#,Json,Json.net,这是我的json模式文件 { "$schema": "http://json-schema.org/draft-04/schema#", "title": "BootNotificationResponse", "type": "object", "properties": { "status": { "type": "string", "enum": [ "Accepted", "Pending",
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "BootNotificationResponse",
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"Accepted",
"Pending",
"Rejected"
]
},
"currentTime": {
"type": "string",
"format": "date-time"
},
"interval": {
"type": "number"
}
},
"additionalProperties": false,
"required": [
"status",
"currentTime",
"interval"
]
}
我试过密码
string file = File.ReadAllText(@"../../json/BootNotificationResponse.json");
Console.WriteLine(file);
JsonSchema.Parse(file);
文件指向json模式位置
有例外
System.ArgumentException: Can not convert Array to Boolean.
我遵循了Newtonsoft网站的示例代码
我如何解决这个错误
请评论
谢谢。使用NewtonSoft,您将看到“对象缺少必需的属性:status、currentTime、interval”。您需要从模式中删除以下内容以使其适用于此实现
"required": [
"status",
"currentTime",
"interval"
]
或者,如果您想要修复它,您需要更新JSON模式以包含以下定义
{
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'BootNotificationResponse',
'definitions': {
'BootNotificationResponse': {
'type': 'object',
'properties': {
'status': {
'type': 'string',
'enum': [
'Accepted',
'Pending',
'Rejected'
]
},
'currentTime': {
'type': 'string',
'format': 'date-time'
},
'interval': {
'type': 'number'
}
},
'additionalProperties': false,
'required': [
'status',
'currentTime',
'interval'
]
}
}
}
抱歉,我错过了json模式中的“}”,我尝试了这个json{“状态”:“已接受”,“当前时间”:“2013-02-01T20:53:32.486Z”,“间隔”:300}我没有错误。但我在代码中发布的json模式仍然有错误。@user3773632-我不确定你的意思“我在代码中发布的json模式有错误”。如果您希望原始模式正常工作,则需要将“required”属性与其关联的数组一起删除,或者可以使用提供的使用“definitions”属性封装模式的模式。