本文整理汇总了C#中JsonValue.As方法的典型用法代码示例。如果您正苦于以下问题:C# JsonValue.As方法的具体用法?C# JsonValue.As怎么用?C# JsonValue.As使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonValue
的用法示例。
在下文中一共展示了JsonValue.As方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasType
private static bool HasType(JsonValue value, string type)
{
switch (type)
{
case "object":
return value is JsonObject;
case "array":
return value is JsonArray;
case "string":
return value is JsonText;
case "boolean":
return value is JsonTrue || value is JsonFalse;
case "null":
return value is JsonNull;
case "integer":
return value is JsonNumber && value.As<JsonNumber>().IsInteger();
case "number":
return value is JsonNumber;
default:
return false;
}
}
示例2: Can_Deserialize_JsonValue
public void Can_Deserialize_JsonValue()
{
var json = simple.ToJson();
var jsonValue = new JsonValue(json);
var fromJson = jsonValue.As<SimpleObj>();
Assert.That(fromJson.value1, Is.EqualTo(simple.value1));
Assert.That(fromJson.value2, Is.EqualTo(simple.value2));
}
示例3: IsValid
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback)
{
bool succeeded = true;
JsonObject target = value.As<JsonObject>();
if (target == null)
return true;
foreach (string property in byName.Keys)
if (target.Contains(property))
foreach (string dependency in byName[property])
if (target.Contains(dependency) == false)
{
JsonPathSegment segment = new JsonPropertySegment(property);
callback.Fail(segment, value, $"The dependency is not valid. Missing property: {dependency}.");
succeeded = false;
}
foreach (string property in byRule.Keys)
{
if (target.Contains(property))
{
JsonSchemaRule rule = byRule[property];
JsonPathSegment segment = new JsonPropertySegment(property);
JsonSchemaCallback scope = callback.Scope(segment);
if (rule.IsValid(definitions, value, scope) == false)
{
callback.Add(scope);
succeeded = false;
}
}
}
return succeeded;
}