-Examples!

This commit is contained in:
James Newton-King
2013-01-28 00:07:21 +13:00
parent fd7970a3c3
commit 70ace8d527
115 changed files with 1120 additions and 210 deletions
@@ -9,14 +9,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Bson
{
public class DeserializeFromBson
{
#region Types
public class Event
{
public string Name { get; set; }
public DateTime StartDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
byte[] data = Convert.FromBase64String("MQAAAAJOYW1lAA8AAABNb3ZpZSBQcmVtaWVyZQAJU3RhcnREYXRlAMDgKWE8AQAAAA==");
MemoryStream ms = new MemoryStream(data);
@@ -29,6 +32,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Bson
Console.WriteLine(e.Name);
// Movie Premiere
}
#endregion
}
}
}
@@ -9,14 +9,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Bson
{
public class DeserializeFromBsonCollection
{
#region Types
public class Event
{
public string Name { get; set; }
public DateTime StartDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
byte[] data = Convert.FromBase64String("awAAAAMwADAAAAACTmFtZQAOAAAATW92aWUgcHJlbWllcgAJU3RhcnREYXRlAMDgKWE8AQAAAAMxADAAAAACTmFtZQAOAAAATW92aWUgcHJlbWllcgAJU3RhcnREYXRlAMDgKWE8AQAAAAA=");
MemoryStream ms = new MemoryStream(data);
@@ -31,6 +34,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Bson
Console.WriteLine(events.Count);
// 2
}
#endregion
}
}
}
@@ -10,14 +10,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Bson
{
public class SerializeToBson
{
#region Types
public class Event
{
public string Name { get; set; }
public DateTime StartDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
Event e = new Event
{
Name = "Movie Premiere",
@@ -35,6 +38,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Bson
Console.WriteLine(data);
// MQAAAAJOYW1lAA8AAABNb3ZpZSBQcmVtaWVyZQAJU3RhcnREYXRlAMDgKWE8AQAAAA==
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Json
{
public void Example()
{
#region Usage
string json = @"{
'CPU': 'Intel',
'PSU': '500W',
@@ -43,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Json
// Token: String, Value: 200 gigabype hard drive
// Token: EndArray
// Token: EndObject
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Json
{
public void Example()
{
#region Usage
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
@@ -43,6 +44,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Json
// "200 gigabype hard drive"
// ]
// }
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o1 = new JObject
{
{"String", "A string!"},
@@ -41,6 +42,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(Object.ReferenceEquals(o1, o2));
// false
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public class CreateJsonAnonymousObject
{
#region Types
public class Post
{
public string Title { get; set; }
@@ -15,9 +16,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
public string Link { get; set; }
public IList<string> Categories { get; set; }
}
#endregion
public void Example()
{
#region Usage
List<Post> posts = new List<Post>
{
new Post
@@ -72,6 +75,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// ]
// }
// }
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = new JObject
{
{"Cpu", "Intel"},
@@ -32,6 +33,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// "SSD"
// ]
// }
#endregion
}
}
}
@@ -8,6 +8,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public class CreateJsonDeclaratively
{
#region Types
public class Post
{
public string Title { get; set; }
@@ -15,13 +16,16 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
public string Link { get; set; }
public IList<string> Categories { get; set; }
}
#endregion
private List<Post> GetPosts()
{
return null;
}
public void Example()
{
#region Usage
List<Post> posts = GetPosts();
JObject rss =
@@ -73,6 +77,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// ]
// }
// }
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
dynamic product = new JObject();
product.ProductName = "Elbow Grease";
product.Enabled = true;
@@ -30,6 +31,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// "OnSale"
// ]
// }
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JTokenWriter writer = new JTokenWriter();
writer.WriteStartObject();
writer.WritePropertyName("name1");
@@ -31,6 +32,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// 2
// ]
// }
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JArray array = new JArray();
JValue text = new JValue("Manual text");
JValue date = new JValue(new DateTime(2000, 5, 23));
@@ -17,13 +18,19 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
array.Add(text);
array.Add(date);
string json = array.ToString();
JObject o = new JObject();
o["MyArray"] = array;
string json = o.ToString();
Console.WriteLine(json);
// [
// "Manual text",
// "2000-05-23T00:00:00"
// ]
// {
// "MyArray": [
// "Manual text",
// "2000-05-23T00:00:00"
// ]
// }
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = new JObject
{
{"Cpu", "Intel"},
@@ -44,6 +45,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// String - SSD
// EndArray
// EndObject
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = new JObject
{
{"name1", "value1"},
@@ -32,6 +33,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// 2
// ]
// }
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JValue s1 = new JValue("A string");
JValue s2 = new JValue("A string");
JValue s3 = new JValue("A STRING");
@@ -39,6 +40,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(JToken.DeepEquals(s1, o1["String"]));
// true
#endregion
}
}
}
@@ -9,6 +9,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public class DeserializeWithLinq
{
#region Types
public class BlogPost
{
public string Title { get; set; }
@@ -17,9 +18,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
public string Body { get; set; }
public DateTime PostedDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
string json = @"[
{
'Title': 'Json.NET is awesome!',
@@ -47,6 +50,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(blogPosts[0].Body);
// <h3>Title!</h3>
// <p>Content!</p>
#endregion
}
}
}
@@ -8,15 +8,18 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public class FromObject
{
#region Types
public class Computer
{
public string Cpu { get; set; }
public int Memory { get; set; }
public IList<string> Drives { get; set; }
}
#endregion
public void Example()
{
#region Usage
JValue i = (JValue)JToken.FromObject(12345);
Console.WriteLine(i.Type);
@@ -61,6 +64,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// "DVD",
// "SSD"
// ]
#endregion
}
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = new JObject
{
{ "name1", "value1" },
@@ -29,6 +30,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
}
// name1 - value1
// name2 - value2
#endregion
}
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JValue v1 = new JValue("1");
int i = (int)v1;
@@ -50,6 +51,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine((dt != null) ? dt.ToString() : "{null}");
// {null}
#endregion
}
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JValue s = new JValue("A string value");
Console.WriteLine(s.Value.GetType().Name);
@@ -23,6 +24,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// Uri
Console.WriteLine(u.Value);
// http://www.google.com/
#endregion
}
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
string json = @"{
'channel': {
'title': 'Star Wars',
@@ -48,6 +49,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// ]
// }
// }
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JToken t1 = JToken.Parse("{}");
Console.WriteLine(t1.Type);
@@ -29,6 +30,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(t4.Type);
// String
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
string json = @"[
'Small',
'Medium',
@@ -24,6 +25,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// "Medium",
// "Large"
// ]
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
string json = @"{
CPU: 'Intel',
Drives: [
@@ -28,6 +29,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// "500 gigabyte hard drive"
// ]
// }
#endregion
}
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
string json = @"{
'channel': {
'title': 'James Newton-King',
@@ -62,6 +63,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(string.Join(", ", categoriesText));
// Json.NET, CodePlex
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
string json = @"[
{
'Title': 'Json.NET is awesome!',
@@ -29,16 +30,20 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
dynamic blogPost = blogPosts[0];
string title = blogPost.Title;
Console.WriteLine(title);
// Json.NET is awesome!
string author = blogPost.Author.Name;
Console.WriteLine(author);
// James Newton-King
DateTime postDate = blogPost.Date;
Console.WriteLine(postDate);
// 23/01/2013 7:30:00 p.m.
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
string json = @"{
'channel': {
'title': 'James Newton-King',
@@ -48,7 +49,6 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
Console.WriteLine(item);
}
//LINQ to JSON beta
//Json.NET 1.3 + New license + Now on CodePlex
@@ -62,10 +62,10 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
Console.WriteLine(c.Category + " - Count: " + c.Count);
}
//Json.NET - Count: 2
//LINQ - Count: 1
//CodePlex - Count: 1
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = JObject.Parse(@"{
'Stores': [
'Lambton Quay',
@@ -55,6 +56,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(productName);
// Elbow Grease
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = JObject.Parse(@"{
'Stores': [
'Lambton Quay',
@@ -55,6 +56,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(totalPrice);
// 149.95
#endregion
}
}
}
}
@@ -12,6 +12,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
byte[] data = Convert.FromBase64String("KQAAAAJuYW1lMQAHAAAAdmFsdWUxAAJuYW1lMgAHAAAAdmFsdWUyAAA=");
MemoryStream ms = new MemoryStream(data);
@@ -25,6 +26,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(value);
// value1
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o1 = JObject.Parse(File.ReadAllText(@"c:\videogames.json"));
// read JSON directly from a file
@@ -19,6 +20,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
JObject o2 = (JObject) JToken.ReadFrom(reader);
}
#endregion
}
}
}
@@ -9,6 +9,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public class SerializeWithLinq
{
#region Types
public class BlogPost
{
public string Title { get; set; }
@@ -17,9 +18,11 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
public string Body { get; set; }
public DateTime PostedDate { get; set; }
}
#endregion
public void Example()
{
#region Usage
IList<BlogPost> blogPosts = new List<BlogPost>
{
new BlogPost
@@ -29,7 +32,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
AuthorTwitter = "JamesNK",
PostedDate = new DateTime(2013, 1, 23, 19, 30, 0),
Body = @"<h3>Title!</h3>
<p>Content!</p>"
<p>Content!</p>"
}
};
@@ -61,6 +64,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
// "BodyHtml": "&lt;h3&gt;Title!&lt;/h3&gt;\r\n&lt;p&gt;Content!&lt;/p&gt;"
// }
// ]
#endregion
}
}
}
}
@@ -8,13 +8,16 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public class ToObjectComplex
{
#region Types
public class Person
{
public string Name { get; set; }
}
#endregion
public void Example()
{
#region Usage
string json = @"{
'd': [
{
@@ -37,6 +40,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(person[1].Name);
// Mike Smith
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JValue v1 = new JValue(true);
bool b = v1.ToObject<bool>();
@@ -26,6 +27,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(s);
// "True"
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JValue v1 = new JValue(true);
bool b = (bool)v1.ToObject(typeof(bool));
@@ -26,6 +27,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(s);
// "True"
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = JObject.Parse(@"{'string1':'value','integer2':99,'datetime3':'2000-05-23T00:00:00'}");
Console.WriteLine(o.ToString());
@@ -25,6 +26,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(o.ToString(Formatting.None, new JavaScriptDateTimeConverter()));
// {"string1":"value","integer2":99,"datetime3":new Date(959032800000)}
#endregion
}
}
}
@@ -11,10 +11,12 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = JObject.Parse(@"{'string1':'value','integer2':99,'datetime3':'2000-05-23T00:00:00'}");
Console.WriteLine(o.ToString(Formatting.None, new JavaScriptDateTimeConverter()));
// {"string1":"value","integer2":99,"datetime3":new Date(959032800000)}
#endregion
}
}
}
@@ -12,6 +12,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject o = new JObject
{
{"name1","value1"},
@@ -28,6 +29,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
Console.WriteLine(data);
// KQAAAAJuYW1lMQAHAAAAdmFsdWUxAAJuYW1lMgAHAAAAdmFsdWUyAAA=
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
public void Example()
{
#region Usage
JObject videogameRatings = new JObject(
new JProperty("Halo", 9),
new JProperty("Starcraft", 9),
@@ -24,6 +25,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
{
videogameRatings.WriteTo(writer);
}
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
JsonSchema schema = new JsonSchema();
schema.Type = JsonSchemaType.Object;
schema.Properties = new Dictionary<string, JsonSchema>
@@ -52,6 +53,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
Console.WriteLine(valid);
// true
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -34,6 +35,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
Console.WriteLine(valid);
// true
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -42,6 +43,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
}
// Invalid type. Expected String but got Null. Line 2, position 21.
// Invalid type. Expected String but got Float. Line 3, position 51.
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -41,6 +42,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
}
// Invalid type. Expected String but got Null. Line 2, position 21.
// Invalid type. Expected String but got Float. Line 3, position 51.
#endregion
}
}
}
@@ -1,32 +0,0 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public class JsonSchemaLoad
{
public void Example()
{
string schemaJson = @"{'type': 'object'}";
JsonSchema schema;
using (TextReader file = File.OpenText(@"c:\schema.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
schema = JsonSchema.Read(reader);
}
JObject o = JObject.Parse(@"{}");
bool valid = o.IsValid(schema);
Console.WriteLine(valid);
// true
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -34,6 +35,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
}
// name - String
// hobbies - Array
#endregion
}
}
}
@@ -9,14 +9,17 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public class JsonValidatingReaderAndSerializer
{
#region Types
public class Person
{
public string Name { get; set; }
public IList<string> Hobbies { get; set; }
}
#endregion
public void Example()
{
#region Usage
string schemaJson = @"{
'description': 'A person',
'type': 'object',
@@ -52,6 +55,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
Console.WriteLine(isValid);
// true
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
// read file into a string and parse JsonSchema from the string
JsonSchema schema1 = JsonSchema.Parse(File.ReadAllText(@"c:\schema.json"));
@@ -20,6 +21,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
JsonSchema schema2 = JsonSchema.Read(reader);
}
#endregion
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
string schemaJson;
JsonSchemaResolver resolver = new JsonSchemaResolver();
@@ -50,6 +51,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
Console.WriteLine(valid);
// true
#endregion
}
}
}
}
@@ -11,6 +11,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
public void Example()
{
#region Usage
JsonSchema schema = JsonSchema.Parse(@"{'type': 'object'}");
// serialize JsonSchema to a string and then write string to a file
@@ -22,6 +23,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Schema
{
schema.WriteTo(writer);
}
#endregion
}
}
}
@@ -36,8 +36,9 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
{
JsonConvert.DeserializeObject<Website>(json);
}
catch (TargetInvocationException)
catch (TargetInvocationException ex)
{
Console.WriteLine(ex);
// Value cannot be null.
// Parameter name: website
}
@@ -49,4 +49,4 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Serializer
#endregion
}
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Xml
{
public void Example()
{
#region Usage
string json = @"{
'@Id': 1,
'Email': 'james@example.com',
@@ -40,6 +41,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Xml
// <Description>Creators of fine software products and services.</Description>
// </Team>
// </Root>
#endregion
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Xml
{
public void Example()
{
#region Usage
string xml = @"<?xml version='1.0' standalone='no'?>
<root>
<person id='1'>
@@ -48,6 +49,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Xml
// ]
// }
// }
#endregion
}
}
}
}
@@ -10,6 +10,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Xml
{
public void Example()
{
#region Usage
string xml = @"<person id='1'>
<name>Alan</name>
<url>http://www.google.com</url>
@@ -53,6 +54,7 @@ namespace Newtonsoft.Json.Tests.Documentation.Examples.Xml
// ]
// }
// }
#endregion
}
}
}
}
@@ -135,7 +135,6 @@
<Compile Include="Documentation\Examples\Schema\JTokenIsValid.cs" />
<Compile Include="Documentation\Examples\Schema\RefJsonSchemaResolver.cs" />
<Compile Include="Documentation\Examples\Schema\SaveJsonSchemaToFile.cs" />
<Compile Include="Documentation\Examples\Schema\JsonSchemaLoad.cs" />
<Compile Include="Documentation\Examples\Schema\JsonSchemaParse.cs" />
<Compile Include="Documentation\Examples\Linq\Clone.cs" />
<Compile Include="Documentation\Examples\Linq\ReadJTokenFromBson.cs" />
@@ -76,5 +76,5 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.5.11.15726")]
[assembly: AssemblyFileVersion("4.5.11.15727")]
#endif
@@ -90,7 +90,7 @@ using System.Security;
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.5.0.0")]
#if !PocketPC
[assembly: AssemblyFileVersion("4.5.11.15726")]
[assembly: AssemblyFileVersion("4.5.11.15727")]
#endif
[assembly: CLSCompliant(true)]