-Documentation
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<topic id="QueryJsonSelectTokenEscaped" revisionNumber="1">
|
||||
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<introduction>
|
||||
<para>This sample loads JSON with properties that required escaped queries using <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.SelectToken(System.String)</codeEntityReference>.</para>
|
||||
</introduction>
|
||||
<section>
|
||||
<title>Sample</title>
|
||||
<content>
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\QueryJsonSelectTokenEscaped.cs" region="Usage" title="Usage" />
|
||||
</content>
|
||||
</section>
|
||||
</developerConceptualDocument>
|
||||
</topic>
|
||||
@@ -22,6 +22,18 @@
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="SelectTokenComplex" title="SelectToken Example" />
|
||||
</content>
|
||||
</section>
|
||||
<section>
|
||||
<title>SelectToken with JSONPath</title>
|
||||
<content>
|
||||
<para>SelectToken supports JSONPath queries. Find out more about JSONPath <externalLink>
|
||||
<linkText>here</linkText>
|
||||
<linkUri>http://goessner.net/articles/JsonPath/</linkUri>
|
||||
<linkTarget>_blank</linkTarget>
|
||||
</externalLink>.</para>
|
||||
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\QueryJsonSelectTokenJsonPath.cs" region="Usage" title="SelectToken With JSONPath" />
|
||||
</content>
|
||||
</section>
|
||||
<section>
|
||||
<title>SelectToken with LINQ</title>
|
||||
<content>
|
||||
|
||||
+4
-3
@@ -30,7 +30,7 @@
|
||||
<Topic id="JsonNetVsDotNetSerializers" visible="True" title="Json.NET vs .NET Serializers" />
|
||||
<Topic id="JsonNetVsWindowsDataJson" visible="True" title="Json.NET vs Windows.Data.Json" />
|
||||
<Topic id="Samples" visible="True" isExpanded="true" title="Samples">
|
||||
<Topic id="d6e185d5-c992-44fc-8d8f-d9acc2bbec2f" visible="True" noFile="true" isExpanded="true" title="Serializing JSON">
|
||||
<Topic id="d6e185d5-c992-44fc-8d8f-d9acc2bbec2f" visible="True" noFile="true" title="Serializing JSON">
|
||||
<Topic id="SerializeObject" visible="True" title="Serialize an Object" />
|
||||
<Topic id="SerializeCollection" visible="True" title="Serialize a Collection" />
|
||||
<Topic id="SerializeDictionary" visible="True" title="Serialize a Dictionary" />
|
||||
@@ -67,7 +67,7 @@
|
||||
<Topic id="CustomContractResolver" visible="True" title="Custom IContractResolver" />
|
||||
<Topic id="CustomTraceWriter" visible="True" title="Custom ITraceWriter" />
|
||||
<Topic id="SerializeSerializationBinder" visible="True" title="Custom SerializationBinder" />
|
||||
<Topic id="JsonConstructorAttribute" visible="True" isSelected="true" />
|
||||
<Topic id="JsonConstructorAttribute" visible="True" />
|
||||
<Topic id="JsonConverterAttributeClass" visible="True" title="JsonConverterAttribute on a class" />
|
||||
<Topic id="JsonConverterAttributeProperty" visible="True" title="JsonConverterAttribute on a property" />
|
||||
<Topic id="JsonObjectAttributeOptIn" visible="True" title="JsonObjectAttribute opt-in serialization" />
|
||||
@@ -91,7 +91,7 @@
|
||||
<Topic id="DeserializeDateFormatString" visible="True" title="Deserialize DateFormatString" />
|
||||
<Topic id="SerializeDateFormatString" visible="True" title="Serialize DateFormatString" />
|
||||
</Topic>
|
||||
<Topic id="68b9fad2-5436-4e35-a734-9b9d751cc3e5" visible="True" noFile="true" title="LINQ to JSON">
|
||||
<Topic id="68b9fad2-5436-4e35-a734-9b9d751cc3e5" visible="True" noFile="true" isExpanded="true" title="LINQ to JSON">
|
||||
<Topic id="CreateJsonManually" visible="True" title="Create JSON manually" />
|
||||
<Topic id="CreateJsonCollectionInitializer" visible="True" title="Create JSON using Collection Initializers" />
|
||||
<Topic id="CreateJsonDeclaratively" visible="True" title="Create JSON declaratively with LINQ" />
|
||||
@@ -110,6 +110,7 @@
|
||||
<Topic id="QueryJsonDynamic" visible="True" title="Querying JSON with dynamic" />
|
||||
<Topic id="QueryJsonLinq" visible="True" title="Querying JSON with LINQ" />
|
||||
<Topic id="QueryJsonSelectToken" visible="True" title="Querying JSON with SelectToken" />
|
||||
<Topic id="QueryJsonSelectTokenEscaped" visible="True" isSelected="true" title="Querying JSON with SelectToken and escaped properties" />
|
||||
<Topic id="QueryJsonSelectTokenWithLinq" visible="True" title="Querying JSON with SelectToken and LINQ" />
|
||||
<Topic id="QueryJsonSelectTokenJsonPath" visible="True" title="Querying JSON with JSONPath" />
|
||||
<Topic id="ReadJson" visible="True" title="Read JSON from a file" />
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="icons\favicon.ico" />
|
||||
<None Include="Samples\Linq\QueryJsonSelectTokenEscaped.aml" />
|
||||
<None Include="Samples\Serializer\JsonConstructorAttribute.aml" />
|
||||
<None Include="Samples\Json\ReadMultipleContentWithJsonReader.aml" />
|
||||
<None Include="Samples\Serializer\SerializeImmutableCollections.aml" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,7 @@
|
||||
<Compile Include="Documentation\Samples\Linq\QueryJsonSelectToken.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Documentation\Samples\Linq\QueryJsonSelectTokenEscaped.cs" />
|
||||
<Compile Include="Documentation\Samples\Linq\QueryJsonSelectTokenJsonPath.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user