这是我的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。
我该如何解决这个错误?
请发表评论
感谢。
答案 0 :(得分:3)
使用NewtonSoft的Online Schema Validator,你会看到"对象缺少必需的属性: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'
]
}
}
}