本文整理匯總了C#中Newtonsoft.Json.Schema.JSchemaValidatingReader.ReadAsDateTimeOffset方法的典型用法代碼示例。如果您正苦於以下問題:C# JSchemaValidatingReader.ReadAsDateTimeOffset方法的具體用法?C# JSchemaValidatingReader.ReadAsDateTimeOffset怎麽用?C# JSchemaValidatingReader.ReadAsDateTimeOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Newtonsoft.Json.Schema.JSchemaValidatingReader
的用法示例。
在下文中一共展示了JSchemaValidatingReader.ReadAsDateTimeOffset方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadDateTimes_ReadAsDateTimeOffset
public void ReadDateTimes_ReadAsDateTimeOffset()
{
string schemaJson = @"{
""type"":""array"",
""items"":{
""type"":""string"",
""minLength"":21
}
}";
string json = @"[
""2000-12-02T05:06:02+00:00"",
""2000-12-02T05:06:02Z"",
1
]";
SchemaValidationEventArgs a = null;
JSchemaValidatingReader reader = new JSchemaValidatingReader(new JsonTextReader(new StringReader(json)));
reader.ValidationEventHandler += (sender, args) => { a = args; };
reader.Schema = JSchema.Parse(schemaJson);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsNull(a);
reader.ReadAsDateTimeOffset();
Assert.AreEqual(JsonToken.Date, reader.TokenType);
Assert.IsNull(a);
reader.ReadAsString();
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.IsNotNull(a);
StringAssert.AreEqual(@"String '2000-12-02T05:06:02Z' is less than minimum length of 21. Path '[1]', line 3, position 25.", a.Message);
Assert.AreEqual("2000-12-02T05:06:02Z", a.ValidationError.Value);
a = null;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Integer, reader.TokenType);
Assert.IsNotNull(a);
StringAssert.AreEqual("Invalid type. Expected String but got Integer. Path '[2]', line 4, position 4.", a.Message);
Assert.AreEqual(1, a.ValidationError.Value);
a = null;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsNull(a);
}