[英]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.