1
<?xml version="1.0" encoding="utf-8"?>
2
<topic id="QueryingLINQtoJSON" revisionNumber="1">
3
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
5
<para>LINQ to JSON provides a number of methods for getting data from its objects. The index methods on JObject/JArray let you quickly get data by its property name
6
on an object or index in a collection, while <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Children</codeEntityReference> lets you get ranges
7
of data as <codeInline>IEnumerable<JToken></codeInline> to then query using LINQ.</para>
11
<title>Getting values by Property Name or Collection Index</title>
13
<!-- Uncomment this to create a sub-section outline
15
<para>The simplest way to get a value from LINQ to JSON is to use the
16
<codeEntityReference>P:Newtonsoft.Json.Linq.JToken.Item(System.Object)</codeEntityReference> index on
17
JObject/JArray and then cast the returned <codeEntityReference>T:Newtonsoft.Json.Linq.JValue</codeEntityReference> to the type you want.
20
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonSimpleQuerying" title="Getting JSON Values" />
25
<title>Querying with LINQ</title>
27
<para>JObject/JArray can also be queried using LINQ. <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Children</codeEntityReference>
28
returns the children values of a JObject/JArray
29
as an <codeInline>IEnumerable<JToken></codeInline> that can then be queried with the standard Where/OrderBy/Select LINQ operators.</para>
32
<para><codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Children</codeEntityReference> returns all the children of a token. If it is a
33
JObject it will return a collection of properties to work with and if
34
it is a JArray you will get a collection of the array's values.</para>
37
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonQuerying" title="Querying JSON" />
39
<para>LINQ to JSON can also be used to manually convert JSON to a .NET object.</para>
41
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonDeserializeObject" title="Deserializing Using LINQ Objects" />
43
<para>Manually serializing and deserializing between .NET objects is useful when you are
44
working with JSON that doesn't closely match your .NET objects.</para>
46
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonDeserializeExample" title="Deserializing Using LINQ Example" />
51
<linkText>LINQ to JSON</linkText>
52
<linkUri>LINQtoJSON.htm</linkUri>
53
<linkTarget>_self</linkTarget>
56
<codeEntityReference>P:Newtonsoft.Json.Linq.JToken.Item(System.Object)</codeEntityReference>
57
<codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Children</codeEntityReference>
59
</developerConceptualDocument>
b'\\ No newline at end of file'