简体   繁体   中英

Newtonsoft JsonSchema.Parse failed

here is my json schema file

{
"$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"
]
}

and I tried codes

        string file = File.ReadAllText(@"../../json/BootNotificationResponse.json");

        Console.WriteLine(file);

        JsonSchema.Parse(file);

file points json schema location.

there was exception.

 System.ArgumentException: Can not convert Array to Boolean.

I followed example code site Newtonsoft.

How can I solved this error?

please comment

thanks.

Use NewtonSoft's Online Schema Validator and you will see "Required properties are missing from object: status, currentTime, interval." You will need to remove the following from your schema to make it work for this implementation.

"required": [
"status",
"currentTime",
"interval"
]

or if you want to fix it you will need to update the JSON schema to include the definitions like

 {
     '$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'
             ]
         }
      }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM