-JSON Schema fixes
-Fixed static values being included with fields serialization -Examples! (work in progress)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Examples.Linq
|
||||
{
|
||||
public class DeserializeWithLinq
|
||||
{
|
||||
public class BlogPost
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string AuthorName { get; set; }
|
||||
public string AuthorTwitter { get; set; }
|
||||
public string Body { get; set; }
|
||||
public DateTime PostedDate { get; set; }
|
||||
}
|
||||
|
||||
public void Example()
|
||||
{
|
||||
string json = @"[
|
||||
{
|
||||
""Title"": ""Json.NET is awesome!"",
|
||||
""Author"": {
|
||||
""Name"": ""James Newton-King"",
|
||||
""Twitter"": ""@JamesNK"",
|
||||
""Picture"": ""/jamesnk.png""
|
||||
},
|
||||
""Date"": ""2013-01-23T19:30:00"",
|
||||
""BodyHtml"": ""<h3>Title!</h3>\r\n<p>Content!</p>""
|
||||
}
|
||||
]";
|
||||
|
||||
JArray blogPostArray = JArray.Parse(json);
|
||||
|
||||
IList<BlogPost> blogPosts = blogPostArray.Select(p => new BlogPost
|
||||
{
|
||||
Title = (string) p["Title"],
|
||||
AuthorName = (string) p["Author"]["Name"],
|
||||
AuthorTwitter = (string) p["Author"]["Twitter"],
|
||||
PostedDate = (DateTime) p["Date"],
|
||||
Body = HttpUtility.HtmlDecode((string) p["BodyHtml"])
|
||||
}).ToList();
|
||||
|
||||
Console.WriteLine(blogPosts[0].Body);
|
||||
// <h3>Title!</h3>
|
||||
// <p>Content!</p>
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user