Files
Newtonsoft.Json/Src/Newtonsoft.Json.Tests/Documentation/Samples/Schema/JTokenIsValid.cs
T
James Newton-King 6965fcfa46 -Fixed potential race condition serializing F# objects
-Fixed schema divisible sometimes incorrectly validating to false
-Fixed not calling virtual ShouldSerialize methods
2014-03-31 15:47:36 +13:00

39 lines
1013 B
C#

using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Samples.Schema
{
public class JTokenIsValid
{
public void Example()
{
#region Usage
JsonSchema schema = JsonSchema.Parse(@"{
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}");
JObject person = JObject.Parse(@"{
'name': 'James',
'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}");
IList<string> errorMessages;
bool valid = person.IsValid(schema, out errorMessages);
Console.WriteLine(valid);
// true
#endregion
}
}
}