當前位置: 首頁>>代碼示例>>C#>>正文


C# Schema.JsonSchemaBuilder類代碼示例

本文整理匯總了C#中Newtonsoft.Json.Schema.JsonSchemaBuilder的典型用法代碼示例。如果您正苦於以下問題:C# JsonSchemaBuilder類的具體用法?C# JsonSchemaBuilder怎麽用?C# JsonSchemaBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonSchemaBuilder類屬於Newtonsoft.Json.Schema命名空間,在下文中一共展示了JsonSchemaBuilder類的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.Parse(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:Gert-Cominotto,項目名稱:MvvmCross,代碼行數:29,代碼來源:JsonSchemaBuilderTests.cs

示例2: MultipleTypes

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

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

      Assert.AreEqual("Age", schema.Description);
      Assert.AreEqual(JsonSchemaType.String | JsonSchemaType.Integer, schema.Type);
    }
開發者ID:Gert-Cominotto,項目名稱:MvvmCross,代碼行數:13,代碼來源:JsonSchemaBuilderTests.cs

示例3: UnresolvedReference

    public void UnresolvedReference()
    {
      ExceptionAssert.Throws<Exception>(@"Could not resolve schema reference 'MyUnresolvedReference'.",
        () =>
          {
            string json = @"{
  ""id"":""CircularReferenceArray"",
  ""description"":""CircularReference"",
  ""type"":[""array""],
  ""items"":{""$ref"":""MyUnresolvedReference""}
}";

            JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
            JsonSchema schema = builder.Read(new JsonTextReader(new StringReader(json)));
          });
    }
開發者ID:GCC-Autobahn,項目名稱:Newtonsoft.Json,代碼行數: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.Parse(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:Gert-Cominotto,項目名稱:MvvmCross,代碼行數:15,代碼來源:JsonSchemaBuilderTests.cs

示例5: UnresolvedReference

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

      JsonSchemaBuilder builder = new JsonSchemaBuilder(new JsonSchemaResolver());
      JsonSchema schema = builder.Parse(new JsonTextReader(new StringReader(json)));
    }
開發者ID:Gert-Cominotto,項目名稱:MvvmCross,代碼行數:12,代碼來源:JsonSchemaBuilderTests.cs

示例6: Options

    public void Options()
    {
      string json = @"{
  ""description"":""NZ Island"",
  ""type"":""string"",
  ""options"":
  [
    {""value"":""NI"",""label"":""North Island""},
    {""value"":""SI"",""label"":""South Island""}
  ]
}";

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

      Assert.AreEqual("NZ Island", schema.Description);
      Assert.AreEqual(JsonSchemaType.String, schema.Type);

      Assert.AreEqual(2, schema.Options.Count);
      Assert.AreEqual("North Island", schema.Options[new JValue("NI")]);
      Assert.AreEqual("South Island", schema.Options[new JValue("SI")]);
    }
開發者ID:Gert-Cominotto,項目名稱:MvvmCross,代碼行數:22,代碼來源:JsonSchemaBuilderTests.cs

示例7: DefaultPrimitiveType

    public void DefaultPrimitiveType()
    {
      string json = @"{
  ""description"":""DefaultPrimitiveType"",
  ""default"":1.1
}";

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

      Assert.AreEqual("DefaultPrimitiveType", schema.Description);
      Assert.AreEqual(1.1, (double)schema.Default);
    }
開發者ID:Gert-Cominotto,項目名稱:MvvmCross,代碼行數:13,代碼來源:JsonSchemaBuilderTests.cs

示例8: DisallowSingleType

    public void DisallowSingleType()
    {
      string json = @"{
  ""description"":""DisallowSingleType"",
  ""disallow"":""string""
}";

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

      Assert.AreEqual("DisallowSingleType", schema.Description);
      Assert.AreEqual(JsonSchemaType.String, schema.Disallow);
    }
開發者ID:Gert-Cominotto,項目名稱:MvvmCross,代碼行數:13,代碼來源:JsonSchemaBuilderTests.cs

示例9: AdditionalProperties

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

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

      Assert.AreEqual("AdditionalProperties", schema.Description);
      Assert.AreEqual(JsonSchemaType.Object | JsonSchemaType.Boolean, schema.AdditionalProperties.Type);
    }
開發者ID:Gert-Cominotto,項目名稱:MvvmCross,代碼行數:14,代碼來源:JsonSchemaBuilderTests.cs

示例10: 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

示例11: Reference_NonStandardLocation

    public void Reference_NonStandardLocation()
    {
      string json = @"{
  ""properties"": {
    ""bar"": {""$ref"": ""#/common/foo""},
    ""foo"": {""$ref"": ""#/common/foo""}
  },
  ""common"": {
    ""foo"": {""type"": ""integer""}
  }
}";

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

      Assert.AreEqual(schema.Properties["foo"], schema.Properties["bar"]);
    }
開發者ID:GCC-Autobahn,項目名稱:Newtonsoft.Json,代碼行數:17,代碼來源:JsonSchemaBuilderTests.cs

示例12: 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

示例13: AllowAdditionalItems

    public void AllowAdditionalItems()
    {
      string json = @"{
    ""items"": {},
    ""additionalItems"": false
}";

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

      Assert.IsNull(schema.AdditionalItems);
      Assert.AreEqual(false, schema.AllowAdditionalItems);
    }
開發者ID:GCC-Autobahn,項目名稱:Newtonsoft.Json,代碼行數:13,代碼來源:JsonSchemaBuilderTests.cs

示例14: AdditionalItems

    public void AdditionalItems()
    {
      string json = @"{
    ""items"": [],
    ""additionalItems"": {""type"": ""integer""}
}";

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

      Assert.IsNotNull(schema.AdditionalItems);
      Assert.AreEqual(JsonSchemaType.Integer, schema.AdditionalItems.Type);
      Assert.AreEqual(true, schema.AllowAdditionalItems);
    }
開發者ID:GCC-Autobahn,項目名稱:Newtonsoft.Json,代碼行數:14,代碼來源:JsonSchemaBuilderTests.cs

示例15: 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


注:本文中的Newtonsoft.Json.Schema.JsonSchemaBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。