Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
验证Json模式_Json_Validation_Jsonschema - Fatal编程技术网

验证Json模式

验证Json模式,json,validation,jsonschema,Json,Validation,Jsonschema,我在使用API v4时出错。 我试着做: final JsonValidator validator = new JsonValidator(JsonLoader.fromPath("schema.json")); ValidationReport report = validator.validate(data); 但每次出现错误时:#[schema]:未知关键字联系人 schema.json : { "contacts": { "description": "The

我在使用API v4时出错。 我试着做:

final JsonValidator validator = new JsonValidator(JsonLoader.fromPath("schema.json"));
ValidationReport report = validator.validate(data);
但每次出现错误时:#[schema]:未知关键字联系人

schema.json :
{
    "contacts": {
        "description": "The list of contacts",
        "type": "array",
        "optional": true,
        "items": {
            "description": "A contact",
            "type": "object",
            "properties": {
                "givenName": {
                    "description": "Person's first name",
                    "type": "string",
                    "maxLength": 64,
                    "optional": true
                },
                "familyName": {
                    "description": "A person's last name",
                    "type": "string",
                    "maxLength": 64,
                    "optional": true
                }
            }
        }
    }
}

就我所知,您的数据如下->json_data={“contacts”:array}。如果这是真的,那么最外层的东西基本上是一个对象(基本上是完整的json对象本身),对于这个对象,您“可能”需要将从json的“顶级根”开始的模式定义为-> schema.json:

{
"description": "the outer json",
        "type": "object",
        "properties": {
            "contacts": {
                          "description": "The list of contacts",
                          "type": "array",
                          "optional": true,
                          "items": {
                                     "description": "A contact",
                                     "type": "object",
                                     "properties": {
                                     "givenName": {

etc.....

请原谅我的粗糙凹痕。另外,我还没有对此进行测试,请查看它是否有效,如果无效,我建议您提供您的json_数据(至少是示例)和API示例,以便您可以尝试找出哪里出了问题。

据我所知,您的数据如下->json_数据={“联系人”:数组}。如果这是真的,那么最外层的东西基本上是一个对象(基本上是完整的json对象本身),对于这个对象,您“可能”需要将从json的“顶级根”开始的模式定义为-> schema.json:

{
"description": "the outer json",
        "type": "object",
        "properties": {
            "contacts": {
                          "description": "The list of contacts",
                          "type": "array",
                          "optional": true,
                          "items": {
                                     "description": "A contact",
                                     "type": "object",
                                     "properties": {
                                     "givenName": {

etc.....
请原谅我的粗糙凹痕。另外,我还没有对此进行测试,请查看它是否有效,如果无效,我建议您提供您的json_数据(至少是示例)和API示例,以便可以尝试找出哪里出了问题