From 6d91522d6bb08e282345789d25c51cd24288c257 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 2 Oct 2015 21:49:58 +1300 Subject: [PATCH] -Documentation --- .../Linq/QueryJsonSelectTokenEscaped.aml | 14 ++++ Doc/SelectToken.aml | 12 +++ Doc/doc.content | 7 +- Doc/doc.shfbproj | 1 + .../Linq/QueryJsonSelectTokenEscaped.cs | 78 +++++++++++++++++++ .../Newtonsoft.Json.Tests.csproj | 1 + 6 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 Doc/Samples/Linq/QueryJsonSelectTokenEscaped.aml create mode 100644 Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenEscaped.cs diff --git a/Doc/Samples/Linq/QueryJsonSelectTokenEscaped.aml b/Doc/Samples/Linq/QueryJsonSelectTokenEscaped.aml new file mode 100644 index 00000000..4ddbb41b --- /dev/null +++ b/Doc/Samples/Linq/QueryJsonSelectTokenEscaped.aml @@ -0,0 +1,14 @@ + + + + + This sample loads JSON with properties that required escaped queries using M:Newtonsoft.Json.Linq.JToken.SelectToken(System.String). + +
+ Sample + + + +
+
+
\ No newline at end of file diff --git a/Doc/SelectToken.aml b/Doc/SelectToken.aml index aee0b528..fb03eb54 100644 --- a/Doc/SelectToken.aml +++ b/Doc/SelectToken.aml @@ -22,6 +22,18 @@ +
+ SelectToken with JSONPath + + SelectToken supports JSONPath queries. Find out more about JSONPath +here +http://goessner.net/articles/JsonPath/ +_blank +. + + + +
SelectToken with LINQ diff --git a/Doc/doc.content b/Doc/doc.content index 488e7977..7524c2c7 100644 --- a/Doc/doc.content +++ b/Doc/doc.content @@ -30,7 +30,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -110,6 +110,7 @@ + diff --git a/Doc/doc.shfbproj b/Doc/doc.shfbproj index d206408f..52724974 100644 --- a/Doc/doc.shfbproj +++ b/Doc/doc.shfbproj @@ -100,6 +100,7 @@ + diff --git a/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenEscaped.cs b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenEscaped.cs new file mode 100644 index 00000000..8390c9e2 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Documentation/Samples/Linq/QueryJsonSelectTokenEscaped.cs @@ -0,0 +1,78 @@ +#region License +// Copyright (c) 2007 James Newton-King +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +#endregion + +using Newtonsoft.Json.Linq; +#if DNXCORE50 +using Xunit; +using Test = Xunit.FactAttribute; +using Assert = Newtonsoft.Json.Tests.XUnitAssert; +#else +using NUnit.Framework; +#endif +using System; +using System.Collections.Generic; +#if NET20 +using Newtonsoft.Json.Utilities.LinqBridge; +#else +using System.Linq; +#endif +using System.Text; + +namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq +{ + [TestFixture] + public class QueryJsonSelectTokenEscaped : TestFixtureBase + { + [Test] + public void Example() + { + #region Usage + JObject o = JObject.Parse(@"{ + 'Space Invaders': 'Taito', + 'Doom ]|[': 'id', + ""Yar's Revenge"": 'Atari', + 'Government ""Intelligence""': 'Make-Believe' + }"); + + string spaceInvaders = (string)o.SelectToken("['Space Invaders']"); + // Taito + + string doom3 = (string)o.SelectToken("['Doom ]|[']"); + // id + + string yarsRevenge = (string)o.SelectToken("['Yar\\'s Revenge']"); + // Atari + + string governmentIntelligence = (string)o.SelectToken("['Government \"Intelligence\"']"); + // Make-Believe + #endregion + + Assert.AreEqual("Taito", spaceInvaders); + Assert.AreEqual("id", doom3); + Assert.AreEqual("Atari", yarsRevenge); + Assert.AreEqual("Make-Believe", governmentIntelligence); + } + } +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj index 78c45f79..4d0de2a9 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj @@ -109,6 +109,7 @@ Code + Code