当前位置: 首页>>代码示例>>C#>>正文


C# JsonValidatingReader.Read方法代码示例

本文整理汇总了C#中JsonValidatingReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# JsonValidatingReader.Read方法的具体用法?C# JsonValidatingReader.Read怎么用?C# JsonValidatingReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonValidatingReader的用法示例。


在下文中一共展示了JsonValidatingReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Validate

    /// <summary>
    /// Validates the specified <see cref="JToken"/>.
    /// </summary>
    /// <param name="source">The source <see cref="JToken"/> to test.</param>
    /// <param name="schema">The schema to test with.</param>
    /// <param name="validationEventHandler">The validation event handler.</param>
    public static void Validate(this JToken source, JsonSchema schema, ValidationEventHandler validationEventHandler)
    {
      ValidationUtils.ArgumentNotNull(source, "source");
      ValidationUtils.ArgumentNotNull(schema, "schema");

      using (JsonValidatingReader reader = new JsonValidatingReader(source.CreateReader()))
      {
        reader.Schema = schema;
        if (validationEventHandler != null)
          reader.ValidationEventHandler += validationEventHandler;

        while (reader.Read())
        {
        }
      }
    }
开发者ID:argul,项目名称:tri_battle,代码行数:22,代码来源:SchemaExtensions.cs

示例2: BigIntegerDivisibleBy_Fraction

    public void BigIntegerDivisibleBy_Fraction()
    {
      string schemaJson = @"{
  ""type"":""array"",
  ""items"":{
    ""type"":""number"",
    ""divisibleBy"":1.1
  }
}";

      string json = "[999999999999999999999999999999999999999999999999999999999]";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);
      Assert.IsNotNull(validationEventArgs);
      Assert.AreEqual(@"Integer 999999999999999999999999999999999999999999999999999999999 is not evenly divisible by 1.1. Line 1, position 58.", validationEventArgs.Message);
      Assert.AreEqual("[0]", validationEventArgs.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
    }
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:30,代码来源:JsonValidatingReaderTests.cs

示例3: ExtendsStringGreaterThanMaximumLength

    public void ExtendsStringGreaterThanMaximumLength()
    {
      string schemaJson = @"{
  ""extends"":{
    ""type"":""string"",
    ""minLength"":5,
    ""maxLength"":10
  },
  ""maxLength"":9
}";

      List<string> errors = new List<string>();
      string json = "'The quick brown fox jumps over the lazy dog.'";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) =>
        {
          validationEventArgs = args;
          errors.Add(validationEventArgs.Message);
        };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual(1, errors.Count);
      Assert.AreEqual("String 'The quick brown fox jumps over the lazy dog.' exceeds maximum length of 9. Line 1, position 46.", errors[0]);

      Assert.IsNotNull(validationEventArgs);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:31,代码来源:JsonValidatingReaderTests.cs

示例4: MissingNonRequiredProperties

    public void MissingNonRequiredProperties()
    {
      string schemaJson = @"{
  ""description"":""A person"",
  ""type"":""object"",
  ""properties"":
  {
    ""name"":{""type"":""string"",""required"":true},
    ""hobbies"":{""type"":""string"",""required"":false},
    ""age"":{""type"":""integer""}
  }
}";

      string json = "{'name':'James'}";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("name", reader.Value.ToString());

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("James", reader.Value.ToString());
      Assert.IsNull(validationEventArgs);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsNull(validationEventArgs);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:38,代码来源:JsonValidatingReaderTests.cs

示例5: InvalidDataType

    public void InvalidDataType()
    {
      string schemaJson = @"{
  ""type"":""string"",
  ""minItems"":2,
  ""maxItems"":3,
  ""items"":{}
}";

      string json = "[null,null,null,null]";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
      Assert.AreEqual(@"Invalid type. Expected String but got Array. Line 1, position 1.", validationEventArgs.Message);

      Assert.IsNotNull(validationEventArgs);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:23,代码来源:JsonValidatingReaderTests.cs

示例6: BooleanNotInEnum

    public void BooleanNotInEnum()
    {
      string schemaJson = @"{
  ""type"":""array"",
  ""items"":{
    ""type"":""boolean"",
    ""enum"":[true]
  },
  ""maxItems"":3
}";

      string json = "[true,false]";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Boolean, reader.TokenType);
      Assert.AreEqual(null, validationEventArgs);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Boolean, reader.TokenType);
      Assert.AreEqual(@"Value false is not defined in enum. Line 1, position 11.", validationEventArgs.Message);
      Assert.AreEqual("[1]", validationEventArgs.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsNotNull(validationEventArgs);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:36,代码来源:JsonValidatingReaderTests.cs

示例7: FloatExceedsMaxDecimalPlaces

    public void FloatExceedsMaxDecimalPlaces()
    {
      string schemaJson = @"{
  ""type"":""array"",
  ""items"":{
    ""type"":""number"",
    ""divisibleBy"":0.1
  }
}";

      string json = "[1.1,2.2,4.001]";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Float, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Float, reader.TokenType);
      Assert.AreEqual(null, validationEventArgs);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Float, reader.TokenType);
      Assert.AreEqual(@"Float 4.001 is not evenly divisible by 0.1. Line 1, position 14.", validationEventArgs.Message);
      Assert.AreEqual("[2]", validationEventArgs.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsNotNull(validationEventArgs);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:38,代码来源:JsonValidatingReaderTests.cs

示例8: ValidateTypes

    public void ValidateTypes()
    {
      string schemaJson = @"{
  ""description"":""A person"",
  ""type"":""object"",
  ""properties"":
  {
    ""name"":{""type"":""string""},
    ""hobbies"":
    {
      ""type"":""array"",
      ""items"": {""type"":""string""}
    }
  }
}";

      string json = @"{'name':""James"",'hobbies':[""pie"",'cake']}";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      JsonSchema schema = JsonSchema.Parse(schemaJson);
      reader.Schema = schema;
      Assert.AreEqual(schema, reader.Schema);
      Assert.AreEqual(0, reader.Depth);
      Assert.AreEqual("", reader.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
      Assert.AreEqual("", reader.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("name", reader.Value.ToString());
      Assert.AreEqual("name", reader.Path);
      Assert.AreEqual(1, reader.Depth);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("James", reader.Value.ToString());
      Assert.AreEqual(typeof (string), reader.ValueType);
      Assert.AreEqual('"', reader.QuoteChar);
      Assert.AreEqual("name", reader.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("hobbies", reader.Value.ToString());
      Assert.AreEqual('\'', reader.QuoteChar);
      Assert.AreEqual("hobbies", reader.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
      Assert.AreEqual("hobbies", reader.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("pie", reader.Value.ToString());
      Assert.AreEqual('"', reader.QuoteChar);
      Assert.AreEqual("hobbies[0]", reader.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("cake", reader.Value.ToString());
      Assert.AreEqual("hobbies[1]", reader.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
      Assert.AreEqual("hobbies", reader.Path);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
      Assert.AreEqual("", reader.Path);

      Assert.IsFalse(reader.Read());
      
      Assert.IsNull(validationEventArgs);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:78,代码来源:JsonValidatingReaderTests.cs

示例9: ValidateUnrestrictedArray

    public void ValidateUnrestrictedArray()
    {
      string schemaJson = @"{
  ""type"":""array""
}";

      string json = "['pie','cake',['nested1','nested2'],{'nestedproperty1':1.1,'nestedproperty2':[null]}]";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("pie", reader.Value.ToString());

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("cake", reader.Value.ToString());

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("nested1", reader.Value.ToString());

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("nested2", reader.Value.ToString());

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("nestedproperty1", reader.Value.ToString());

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Float, reader.TokenType);
      Assert.AreEqual(1.1, reader.Value);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("nestedproperty2", reader.Value.ToString());

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Null, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsNull(validationEventArgs);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:71,代码来源:JsonValidatingReaderTests.cs

示例10: PatternPropertiesNoAdditionalProperties

    public void PatternPropertiesNoAdditionalProperties()
    {
      string schemaJson = @"{
  ""type"":""object"",
  ""patternProperties"": {
     ""hi"": {""type"":""string""},
     ""ho"": {""type"":""string""}
  },
  ""additionalProperties"": false
}";

      string json = @"{
  ""hi"": ""A string!"",
  ""hide"": ""A string!"",
  ""ho"": 1,
  ""hey"": ""A string!""
}";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual(null, validationEventArgs);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual(null, validationEventArgs);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual(null, validationEventArgs);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);
      Assert.AreEqual("Invalid type. Expected String but got Integer. Line 4, position 10.", validationEventArgs.Message);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
      Assert.AreEqual("Property 'hey' has not been defined and the schema does not allow additional properties. Line 5, position 9.", validationEventArgs.Message);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.IsFalse(reader.Read());
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:61,代码来源:JsonValidatingReaderTests.cs

示例11: NoAdditionalProperties

    public void NoAdditionalProperties()
    {
      string schemaJson = @"{
  ""type"":""array"",
  ""items"": [{""type"":""string""},{""type"":""integer""}],
  ""additionalProperties"": false
}";

      string json = @"[1, 'a', null]";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Integer, reader.TokenType);
      Assert.AreEqual("Invalid type. Expected String but got Integer. Line 1, position 2.", validationEventArgs.Message);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.String, reader.TokenType);
      Assert.AreEqual("Invalid type. Expected Integer but got String. Line 1, position 7.", validationEventArgs.Message);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Null, reader.TokenType);
      Assert.AreEqual("Index 3 has not been defined and the schema does not allow additional items. Line 1, position 13.", validationEventArgs.Message);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsFalse(reader.Read());
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:36,代码来源:JsonValidatingReaderTests.cs

示例12: ExtendsMissingRequiredProperties

    public void ExtendsMissingRequiredProperties()
    {
      string json = "{}";

      List<string> errors = new List<string>();

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { errors.Add(args.Message); };
      reader.Schema = GetExtendedSchema();

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartObject, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndObject, reader.TokenType);

      Assert.AreEqual(1, errors.Count);
      Assert.AreEqual("Required properties are missing from object: secondproperty, firstproperty. Line 1, position 2.", errors[0]);
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:19,代码来源:JsonValidatingReaderTests.cs

示例13: FloatIsNotInEnum

    public void FloatIsNotInEnum()
    {
      string schemaJson = @"{
  ""type"":""array"",
  ""items"":{
    ""type"":""number"",
    ""enum"":[1.1,2.2]
  },
  ""maxItems"":3
}";

      string json = "[1.1,2.2,3.0]";

      Json.Schema.ValidationEventArgs validationEventArgs = null;

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader(json)));
      reader.ValidationEventHandler += (sender, args) => { validationEventArgs = args; };
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.StartArray, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Float, reader.TokenType);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Float, reader.TokenType);
      Assert.AreEqual(null, validationEventArgs);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.Float, reader.TokenType);
      Assert.AreEqual(@"Value 3.0 is not defined in enum. Line 1, position 12.", validationEventArgs.Message);

      Assert.IsTrue(reader.Read());
      Assert.AreEqual(JsonToken.EndArray, reader.TokenType);

      Assert.IsNotNull(validationEventArgs);
    }
开发者ID:phonia,项目名称:CodeLibrary,代码行数:38,代码来源:JsonValidatingReaderTests.cs

示例14: ThrowExceptionWhenNoValidationEventHandler

    public void ThrowExceptionWhenNoValidationEventHandler()
    {
      string schemaJson = @"{
  ""type"":""integer"",
  ""maximum"":5
}";

      JsonValidatingReader reader = new JsonValidatingReader(new JsonTextReader(new StringReader("10")));
      reader.Schema = JsonSchema.Parse(schemaJson);

      Assert.IsTrue(reader.Read());
    }
开发者ID:phonia,项目名称:CodeLibrary,代码行数:12,代码来源:JsonValidatingReaderTests.cs

示例15: ReaderPerformance

        public void ReaderPerformance()
        {
            string json = @"[
    {
        ""id"": 2,
        ""name"": ""An ice sculpture"",
        ""price"": 12.50,
        ""tags"": [""cold"", ""ice""],
        ""dimensions"": {
            ""length"": 7.0,
            ""width"": 12.0,
            ""height"": 9.5
        },
        ""warehouseLocation"": {
            ""latitude"": -78.75,
            ""longitude"": 20.4
        }
    },
    {
        ""id"": 3,
        ""name"": ""A blue mouse"",
        ""price"": 25.50,
        ""dimensions"": {
            ""length"": 3.1,
            ""width"": 1.0,
            ""height"": 1.0
        },
        ""warehouseLocation"": {
            ""latitude"": 54.4,
            ""longitude"": -32.7
        }
    }
]";

            JsonSchema schema = JsonSchema.Parse(@"{
    ""$schema"": ""http://json-schema.org/draft-04/schema#"",
    ""title"": ""Product set"",
    ""type"": ""array"",
    ""items"": {
        ""title"": ""Product"",
        ""type"": ""object"",
        ""properties"": {
            ""id"": {
                ""description"": ""The unique identifier for a product"",
                ""type"": ""number"",
                ""required"": true
            },
            ""name"": {
                ""type"": ""string"",
                ""required"": true
            },
            ""price"": {
                ""type"": ""number"",
                ""minimum"": 0,
                ""exclusiveMinimum"": true,
                ""required"": true
            },
            ""tags"": {
                ""type"": ""array"",
                ""items"": {
                    ""type"": ""string""
                },
                ""minItems"": 1,
                ""uniqueItems"": true
            },
            ""dimensions"": {
                ""type"": ""object"",
                ""properties"": {
                    ""length"": {""type"": ""number"",""required"": true},
                    ""width"": {""type"": ""number"",""required"": true},
                    ""height"": {""type"": ""number"",""required"": true}
                }
            },
            ""warehouseLocation"": {
                ""description"": ""A geographical coordinate"",
                ""type"": ""object"",
                ""properties"": {
                    ""latitude"": { ""type"": ""number"" },
                    ""longitude"": { ""type"": ""number"" }
                }
            }
        }
    }
}");

            using (var tester = new PerformanceTester("Reader"))
            {
                for (int i = 0; i < 5000; i++)
                {
                    JsonTextReader reader = new JsonTextReader(new StringReader(json));
                    JsonValidatingReader validatingReader = new JsonValidatingReader(reader);
                    validatingReader.Schema = schema;

                    while (validatingReader.Read())
                    {
                    }
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:99,代码来源:PerformanceTests.cs


注:本文中的JsonValidatingReader.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。