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


C# JsonSchemaBuilder.Read方法代码示例

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


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

示例1: Simple

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

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("A person", schema.Description);
      Assert.AreEqual(JsonSchemaType.Object, schema.Type);

      Assert.AreEqual(2, schema.Properties.Count);

      Assert.AreEqual(JsonSchemaType.String, schema.Properties["name"].Type);
      Assert.AreEqual(JsonSchemaType.Array, schema.Properties["hobbies"].Type);
      Assert.AreEqual(JsonSchemaType.String, schema.Properties["hobbies"].Items[0].Type);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:29,代码来源:JsonSchemaBuilderTests.cs

示例2: MultipleTypes

    public void MultipleTypes()
    {
      string json = @"{
  ""description"":""Age"",
  ""type"":[""string"", ""integer""]
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("Age", schema.Description);
      Assert.AreEqual(JsonSchemaType.String | JsonSchemaType.Integer, schema.Type);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:13,代码来源:JsonSchemaBuilderTests.cs

示例3: References_Array

    public void References_Array()
    {
      string json = @"{
            ""array"": [{""type"": ""integer""},{""prop"":{""type"": ""object""}}],
            ""properties"": {
                ""array"": {""$ref"": ""#/array/0""},
                ""arrayprop"": {""$ref"": ""#/array/1/prop""}
            }
        }";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual(JsonSchemaType.Integer, schema.Properties["array"].Type);
      Assert.AreEqual(JsonSchemaType.Object, schema.Properties["arrayprop"].Type);
    }
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:16,代码来源:JsonSchemaBuilderTests.cs

示例4: MultipleItems

    public void MultipleItems()
    {
      string json = @"{
  ""description"":""MultipleItems"",
  ""type"":""array"",
  ""items"": [{""type"":""string""},{""type"":""array""}]
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("MultipleItems", schema.Description);
      Assert.AreEqual(JsonSchemaType.String, schema.Items[0].Type);
      Assert.AreEqual(JsonSchemaType.Array, schema.Items[1].Type);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:15,代码来源:JsonSchemaBuilderTests.cs

示例5: EscapedReferences

    public void EscapedReferences()
    {
      string json = @"{
            ""tilda~field"": {""type"": ""integer""},
            ""slash/field"": {""type"": ""object""},
            ""percent%field"": {""type"": ""array""},
            ""properties"": {
                ""tilda"": {""$ref"": ""#/tilda~0field""},
                ""slash"": {""$ref"": ""#/slash~1field""},
                ""percent"": {""$ref"": ""#/percent%25field""}
            }
        }";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual(JsonSchemaType.Integer, schema.Properties["tilda"].Type);
      Assert.AreEqual(JsonSchemaType.Object, schema.Properties["slash"].Type);
      Assert.AreEqual(JsonSchemaType.Array, schema.Properties["percent"].Type);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:20,代码来源:JsonSchemaBuilderTests.cs

示例6: Location

    public void Location()
    {
      string json = @"{
  ""properties"":{
    ""foo"":{
      ""type"":""array"",
      ""items"":[
        {
          ""type"":""integer""
        },
        {
          ""properties"":{
            ""foo"":{
              ""type"":""integer""
            }
          }
        }
      ]
    }
  }
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("#", schema.Location);
      Assert.AreEqual("#/properties/foo", schema.Properties["foo"].Location);
      Assert.AreEqual("#/properties/foo/items/1/properties/foo", schema.Properties["foo"].Items[1].Properties["foo"].Location);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:29,代码来源:JsonSchemaBuilderTests.cs

示例7: PatternProperties

    public void PatternProperties()
    {
      string json = @"{
  ""patternProperties"": {
    ""[abc]"": { ""id"":""Blah"" }
  }
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.IsNotNull(schema.PatternProperties);
      Assert.AreEqual(1, schema.PatternProperties.Count);
      Assert.AreEqual("Blah", schema.PatternProperties["[abc]"].Id);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:15,代码来源:JsonSchemaBuilderTests.cs

示例8: CircularReference

    public void CircularReference()
    {
      string json = @"{
  ""id"":""CircularReferenceArray"",
  ""description"":""CircularReference"",
  ""type"":[""array""],
  ""items"":{""$ref"":""CircularReferenceArray""}
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("CircularReference", schema.Description);
      Assert.AreEqual("CircularReferenceArray", schema.Id);
      Assert.AreEqual(JsonSchemaType.Array, schema.Type);

      Assert.AreEqual(schema, schema.Items[0]);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:18,代码来源:JsonSchemaBuilderTests.cs

示例9: Title

    public void Title()
    {
      string json = @"{
  ""description"":""Title"",
  ""title"":""testtitle""
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("Title", schema.Description);
      Assert.AreEqual("testtitle", schema.Title);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:13,代码来源:JsonSchemaBuilderTests.cs

示例10: Id

    public void Id()
    {
      string json = @"{
  ""description"":""Id"",
  ""id"":""testid""
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("Id", schema.Description);
      Assert.AreEqual("testid", schema.Id);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:13,代码来源:JsonSchemaBuilderTests.cs

示例11: Hidden

    public void Hidden()
    {
      string json = @"{
  ""description"":""Hidden"",
  ""hidden"":true
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("Hidden", schema.Description);
      Assert.AreEqual(true, schema.Hidden);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:13,代码来源:JsonSchemaBuilderTests.cs

示例12: ReadOnly

    public void ReadOnly()
    {
      string json = @"{
  ""description"":""ReadOnly"",
  ""readonly"":true
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("ReadOnly", schema.Description);
      Assert.AreEqual(true, schema.ReadOnly);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:13,代码来源:JsonSchemaBuilderTests.cs

示例13: ExclusiveMinimum_ExclusiveMaximum

    public void ExclusiveMinimum_ExclusiveMaximum()
    {
      string json = @"{
  ""exclusiveMinimum"":true,
  ""exclusiveMaximum"":true
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual(true, schema.ExclusiveMinimum);
      Assert.AreEqual(true, schema.ExclusiveMaximum);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:13,代码来源:JsonSchemaBuilderTests.cs

示例14: AdditionalProperties

    public void AdditionalProperties()
    {
      string json = @"{
  ""description"":""AdditionalProperties"",
  ""type"":[""string"", ""integer""],
  ""additionalProperties"":{""type"":[""object"", ""boolean""]}
}";

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));

      Assert.AreEqual("AdditionalProperties", schema.Description);
      Assert.AreEqual(JsonSchemaType.Object | JsonSchemaType.Boolean, schema.AdditionalProperties.Type);
    }
开发者ID:GCC-Autobahn,项目名称:Newtonsoft.Json,代码行数:14,代码来源:JsonSchemaBuilderTests.cs

示例15: References_IndexNotInteger

    public void References_IndexNotInteger()
    {
      string json = @"{
            ""array"": [{""type"": ""integer""},{""prop"":{""type"": ""object""}}],
            ""properties"": {
                ""array"": {""$ref"": ""#/array/0""},
                ""arrayprop"": {""$ref"": ""#/array/one""}
            }
        }";

      ExceptionAssert.Throws<JsonException>(
        "Could not resolve schema reference '#/array/one'.",
        () =>
        {
          JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
          builder.Read(new JsonTextReader(new StringReader(json)));
        });
    }
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:18,代码来源:JsonSchemaBuilderTests.cs


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