[英]Newtonsoft JsonSchema.Parse failed
这是我的json模式文件
{
"$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的Online Schema Validator ,您将看到“对象缺少必需的属性:状态,currentTime,间隔。” 您需要从架构中删除以下内容,以使其适用于此实现。
"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'
]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.