Files
Newtonsoft.Json/Src/Newtonsoft.Json.Tests/Documentation/Samples/Schema/JTokenIsValid.cs
T
James Newton-King e77fdf285b -Upgraded to Immutable Collections RTM
-Added missing CLSCompliant attributes
2013-09-30 21:53:19 +13:00

39 lines
856 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(@"{
'description': 'A person',
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}");
JObject person = JObject.Parse(@"{
'name': 'James',
'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}");
bool valid = person.IsValid(schema);
Console.WriteLine(valid);
// true
#endregion
}
}
}