初始化

This commit is contained in:
2025-12-11 11:39:02 +08:00
commit 156d6ccb06
1708 changed files with 1162911 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Newtonsoft.Json</id>
<version>6.0.3</version>
<title>Json.NET</title>
<description>Json.NET is a popular high-performance JSON framework for .NET</description>
<authors>James Newton-King</authors>
<language>en-US</language>
<projectUrl>http://james.newtonking.com/json</projectUrl>
<licenseUrl>https://raw.github.com/JamesNK/Newtonsoft.Json/master/LICENSE.md</licenseUrl>
<tags>json</tags>
</metadata>
</package>

View File

@@ -0,0 +1,200 @@
properties {
$zipFileName = "Json60r3.zip"
$majorVersion = "6.0"
$majorWithReleaseVersion = "6.0.3"
$version = GetVersion $majorWithReleaseVersion
$signAssemblies = $false
$signKeyPath = "C:\Development\Releases\newtonsoft.snk"
$buildDocumentation = $false
$buildNuGet = $true
$treatWarningsAsErrors = $false
$baseDir = resolve-path ..
$buildDir = "$baseDir\Build"
$sourceDir = "$baseDir\Src"
$toolsDir = "$baseDir\Tools"
$docDir = "$baseDir\Doc"
$releaseDir = "$baseDir\Release"
$workingDir = "$baseDir\Working"
$builds = @(
@{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net45"; NuGetDir = "net45"; Framework="net-4.0"; Sign=$true},
@{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; Constants="PORTABLE"; FinalDir="Portable"; NuGetDir = "portable-net45+wp80+win8+wpa81"; Framework="net-4.0"; Sign=$true},
@{Name = "Newtonsoft.Json.Portable40"; TestsName = "Newtonsoft.Json.Tests.Portable40"; Constants="PORTABLE40"; FinalDir="Portable40"; NuGetDir = "portable-net40+sl4+wp7+win8"; Framework="net-4.0"; Sign=$true},
@{Name = "Newtonsoft.Json.WinRT"; TestsName = $null; Constants="NETFX_CORE"; FinalDir="WinRT"; NuGetDir = "netcore45"; Framework="net-4.5"; Sign=$true},
@{Name = "Newtonsoft.Json.Net40"; TestsName = "Newtonsoft.Json.Tests.Net40"; Constants="NET40"; FinalDir="Net40"; NuGetDir = "net40"; Framework="net-4.0"; Sign=$true},
@{Name = "Newtonsoft.Json.Net35"; TestsName = "Newtonsoft.Json.Tests.Net35"; Constants="NET35"; FinalDir="Net35"; NuGetDir = "net35"; Framework="net-2.0"; Sign=$true},
@{Name = "Newtonsoft.Json.Net20"; TestsName = "Newtonsoft.Json.Tests.Net20"; Constants="NET20"; FinalDir="Net20"; NuGetDir = "net20"; Framework="net-2.0"; Sign=$true}
)
}
$framework = '4.0x86'
task default -depends Test
# Ensure a clean working directory
task Clean {
Set-Location $baseDir
if (Test-Path -path $workingDir)
{
Write-Output "Deleting Working Directory"
del $workingDir -Recurse -Force
}
New-Item -Path $workingDir -ItemType Directory
}
# Build each solution, optionally signed
task Build -depends Clean {
Write-Host -ForegroundColor Green "Updating assembly version"
Write-Host
Update-AssemblyInfoFiles $sourceDir ($majorVersion + '.0.0') $version
foreach ($build in $builds)
{
$name = $build.Name
$finalDir = $build.FinalDir
$sign = ($build.Sign -and $signAssemblies)
Write-Host -ForegroundColor Green "Building " $name
Write-Host -ForegroundColor Green "Signed " $sign
Write-Host
exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:Platform=Any CPU" /p:OutputPath=bin\Release\$finalDir\ /p:AssemblyOriginatorKeyFile=$signKeyPath "/p:SignAssembly=$sign" "/p:TreatWarningsAsErrors=$treatWarningsAsErrors" "/p:VisualStudioVersion=12.0" (GetConstants $build.Constants $sign) ".\Src\$name.sln" | Out-Default } "Error building $name"
}
}
# Optional build documentation, add files to final zip
task Package -depends Build {
foreach ($build in $builds)
{
$name = $build.TestsName
$finalDir = $build.FinalDir
robocopy "$sourceDir\Newtonsoft.Json\bin\Release\$finalDir" $workingDir\Package\Bin\$finalDir *.dll *.pdb *.xml /NP /XO /XF *.CodeAnalysisLog.xml | Out-Default
}
if ($buildNuGet)
{
New-Item -Path $workingDir\NuGet -ItemType Directory
Copy-Item -Path "$buildDir\Newtonsoft.Json.nuspec" -Destination $workingDir\NuGet\Newtonsoft.Json.nuspec -recurse
New-Item -Path $workingDir\NuGet\tools -ItemType Directory
Copy-Item -Path "$buildDir\install.ps1" -Destination $workingDir\NuGet\tools\install.ps1 -recurse
foreach ($build in $builds)
{
if ($build.NuGetDir)
{
$name = $build.TestsName
$finalDir = $build.FinalDir
$frameworkDirs = $build.NuGetDir.Split(",")
foreach ($frameworkDir in $frameworkDirs)
{
robocopy "$sourceDir\Newtonsoft.Json\bin\Release\$finalDir" $workingDir\NuGet\lib\$frameworkDir *.dll *.pdb *.xml /NP /XO /XF *.CodeAnalysisLog.xml | Out-Default
}
}
}
robocopy $sourceDir $workingDir\NuGet\src *.cs /S /NP /XD Newtonsoft.Json.Tests obj | Out-Default
exec { .\Tools\NuGet\NuGet.exe pack $workingDir\NuGet\Newtonsoft.Json.nuspec -Symbols }
move -Path .\*.nupkg -Destination $workingDir\NuGet
}
if ($buildDocumentation)
{
$mainBuild = $builds | where { $_.Name -eq "Newtonsoft.Json" } | select -first 1
$mainBuildFinalDir = $mainBuild.FinalDir
$documentationSourcePath = "$workingDir\Package\Bin\$mainBuildFinalDir"
Write-Host -ForegroundColor Green "Building documentation from $documentationSourcePath"
# Sandcastle has issues when compiling with .NET 4 MSBuild - http://shfb.codeplex.com/Thread/View.aspx?ThreadId=50652
exec { msbuild "/t:Clean;Rebuild" /p:Configuration=Release "/p:DocumentationSourcePath=$documentationSourcePath" $docDir\doc.shfbproj | Out-Default } "Error building documentation. Check that you have Sandcastle, Sandcastle Help File Builder and HTML Help Workshop installed."
move -Path $workingDir\Documentation\LastBuild.log -Destination $workingDir\Documentation.log
}
Copy-Item -Path $docDir\readme.txt -Destination $workingDir\Package\
Copy-Item -Path $docDir\license.txt -Destination $workingDir\Package\
robocopy $sourceDir $workingDir\Package\Source\Src /MIR /NP /XD .svn bin obj TestResults AppPackages /XF *.suo *.user | Out-Default
robocopy $buildDir $workingDir\Package\Source\Build /MIR /NP /XD .svn /XF runbuild.txt | Out-Default
robocopy $docDir $workingDir\Package\Source\Doc /MIR /NP /XD .svn | Out-Default
robocopy $toolsDir $workingDir\Package\Source\Tools /MIR /NP /XD .svn | Out-Default
exec { .\Tools\7-zip\7za.exe a -tzip $workingDir\$zipFileName $workingDir\Package\* | Out-Default } "Error zipping"
}
# Unzip package to a location
task Deploy -depends Package {
exec { .\Tools\7-zip\7za.exe x -y "-o$workingDir\Deployed" $workingDir\$zipFileName | Out-Default } "Error unzipping"
}
# Run tests on deployed files
task Test -depends Deploy {
foreach ($build in $builds)
{
$name = $build.TestsName
if ($name -ne $null)
{
$finalDir = $build.FinalDir
$framework = $build.Framework
Write-Host -ForegroundColor Green "Copying test assembly $name to deployed directory"
Write-Host
robocopy ".\Src\Newtonsoft.Json.Tests\bin\Release\$finalDir" $workingDir\Deployed\Bin\$finalDir /MIR /NP /XO /XF LinqBridge.dll | Out-Default
Copy-Item -Path ".\Src\Newtonsoft.Json.Tests\bin\Release\$finalDir\Newtonsoft.Json.Tests.dll" -Destination $workingDir\Deployed\Bin\$finalDir\
Write-Host -ForegroundColor Green "Running tests " $name
Write-Host
exec { .\Tools\NUnit\nunit-console.exe "$workingDir\Deployed\Bin\$finalDir\Newtonsoft.Json.Tests.dll" /framework=$framework /xml:$workingDir\$name.xml | Out-Default } "Error running $name tests"
}
}
}
function GetConstants($constants, $includeSigned)
{
$signed = switch($includeSigned) { $true { ";SIGNED" } default { "" } }
return "/p:DefineConstants=`"CODE_ANALYSIS;TRACE;$constants$signed`""
}
function GetVersion($majorVersion)
{
$now = [DateTime]::Now
$year = $now.Year - 2000
$month = $now.Month
$totalMonthsSince2000 = ($year * 12) + $month
$day = $now.Day
$minor = "{0}{1:00}" -f $totalMonthsSince2000, $day
$hour = $now.Hour
$minute = $now.Minute
$revision = "{0:00}{1:00}" -f $hour, $minute
return $majorVersion + "." + $minor
}
function Update-AssemblyInfoFiles ([string] $sourceDir, [string] $assemblyVersionNumber, [string] $fileVersionNumber)
{
$assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$assemblyVersion = 'AssemblyVersion("' + $assemblyVersionNumber + '")';
$fileVersion = 'AssemblyFileVersion("' + $fileVersionNumber + '")';
Get-ChildItem -Path $sourceDir -r -filter AssemblyInfo.cs | ForEach-Object {
$filename = $_.Directory.ToString() + '\' + $_.Name
Write-Host $filename
$filename + ' -> ' + $version
(Get-Content $filename) | ForEach-Object {
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
% {$_ -replace $fileVersionPattern, $fileVersion }
} | Set-Content $filename
}
}

View File

@@ -0,0 +1,93 @@
param($installPath, $toolsPath, $package, $project)
# open json.net splash page on package install
# don't open if json.net is installed as a dependency
try
{
$url = "http://james.newtonking.com/json"
$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])
if ($dte2.ActiveWindow.Caption -eq "Package Manager Console")
{
# user is installing from VS NuGet console
# get reference to the window, the console host and the input history
# show webpage if "install-package newtonsoft.json" was last input
$consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow])
$props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor `
[System.Reflection.BindingFlags]::NonPublic)
$prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1
if ($prop -eq $null) { return }
$hostInfo = $prop.GetValue($consoleWindow)
if ($hostInfo -eq $null) { return }
$history = $hostInfo.WpfConsole.InputHistory.History
$lastCommand = $history | select -last 1
if ($lastCommand)
{
$lastCommand = $lastCommand.Trim().ToLower()
if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json"))
{
$dte2.ItemOperations.Navigate($url) | Out-Null
}
}
}
else
{
# user is installing from VS NuGet dialog
# get reference to the window, then smart output console provider
# show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation
$instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor `
[System.Reflection.BindingFlags]::NonPublic)
$consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor `
[System.Reflection.BindingFlags]::NonPublic)
if ($instanceField -eq $null -or $consoleField -eq $null) { return }
$instance = $instanceField.GetValue($null)
if ($instance -eq $null) { return }
$consoleProvider = $consoleField.GetValue($instance)
if ($consoleProvider -eq $null) { return }
$console = $consoleProvider.CreateOutputConsole($false)
$messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor `
[System.Reflection.BindingFlags]::NonPublic)
if ($messagesField -eq $null) { return }
$messages = $messagesField.GetValue($console)
if ($messages -eq $null) { return }
$operations = $messages -split "=============================="
$lastOperation = $operations | select -last 1
if ($lastOperation)
{
$lastOperation = $lastOperation.ToLower()
$lines = $lastOperation -split "`r`n"
$installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json ") } | select -first 1
if ($installMatch)
{
$dte2.ItemOperations.Navigate($url) | Out-Null
}
}
}
}
catch
{
# stop potential errors from bubbling up
# worst case the splash page won't open
}
# yolo

View File

@@ -0,0 +1,2 @@
powershell -Command "& { [Console]::WindowWidth = 150; [Console]::WindowHeight = 50; Start-Transcript runbuild.txt; Import-Module ..\Tools\PSake\psake.psm1; Invoke-psake .\build.ps1 %*; Stop-Transcript; }"
pause

View File

@@ -0,0 +1,5 @@
cls
Import-Module '..\Tools\PSake\psake.psm1'
Invoke-psake '.\build.ps1' Test -framework 3.5
Remove-Module psake

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ConditionalProperties" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Json.NET has the ability to conditionally serialize properties by placing a ShouldSerialize method on a class.
This funtionality is similar to the <externalLink>
<linkText>XmlSerializer ShouldSerialize feature</linkText>
<linkUri>http://msdn.microsoft.com/en-us/library/53b8022e.aspx</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.</para>
</introduction>
<section>
<title>ShouldSerialize</title>
<content>
<para>To conditionally serialize a property add a boolean method with the same name as the property and then prefixed the method name
with ShouldSerialize. The result of the method determines whether the property is serialized. If the method returns true then the
property will be serialized, if it returns false and the property will be skipped.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="EmployeeShouldSerializeExample" title="Employee class with a ShouldSerialize method" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="ShouldSerializeClassTest" title="ShouldSerialize output" />
</content>
</section>
<section>
<title>IContractResolver</title>
<content>
<para>ShouldSerialize can also be set using an <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>.
Conditionally serializing a property using an IContractResolver is useful if you don't want to place a ShouldSerialize method on a class
or you didn't declare the class and are unable to.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="ShouldSerializeContractResolver" title="Conditional properties with IContractResolver" />
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
<codeEntityReference>P:Newtonsoft.Json.Serialization.JsonProperty.ShouldSerialize</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ContractResolver" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--
<summary>
<para>Optional summary abstract</para>
</summary>
-->
<introduction>
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
interface provides a way to customize how the
JsonSerializer serializes and deserializes .NET objects to JSON without placing attributes on your classes.
</para>
<para>Anything that can be set on an object, collection, property, etc, using attributes or methods to control serialization
can also be set using an IContractResolver.</para>
</introduction>
<!-- Add one or more top-level section elements. These are collapsible.
If using <autoOutline />, add an address attribute to identify it
and specify a title so that it can be jumped to with a hyperlink. -->
<section>
<title>DefaultContractResolver</title>
<content>
<!-- Uncomment this to create a sub-section outline
<autoOutline /> -->
<para>The <codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
is the default resolver used by the
serializer. It provides many avenues of extensibility in the form of
virtual methods that can be overriden.</para>
</content>
</section>
<section>
<title>CamelCasePropertyNamesContractResolver</title>
<content>
<!-- Uncomment this to create a sub-section outline
<autoOutline /> -->
<para><codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
inherits from DefaultContractResolver and simply overrides the JSON
property name to be written in <externalLink>
<linkText>camelcase</linkText>
<linkUri>http://en.wikipedia.org/wiki/CamelCase</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ContractResolver" title="ContractResolver" />
</content>
</section>
<section>
<title>Custom IContractResolver Examples</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
<para>This example sets a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> for a type
using an IContractResolver. Using a contract resolver here is useful because DateTime is not your own type and it is not possible to place a JsonConverterAttribute on it.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConditionalPropertiesTests.cs" region="ShouldSerializeContractResolver" title="Conditional properties with IContractResolver" />
<para>This example sets up <externalLink>
<linkText>conditional serialization for a property</linkText>
<linkUri>ConditionalProperties.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink> using an IContractResolver. This is useful if you want to conditionally serialize a property but don't want to add additional methods to your type.</para>
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Serialization.DefaultContractResolver</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ConvertingJSONandXML" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Json.NET supports converting JSON to XML and vice versa using the
<codeEntityReference>T:Newtonsoft.Json.Converters.XmlNodeConverter</codeEntityReference>.</para>
<para>Elements, attributes, text, comments, character data, processing instructions,
namespaces and the XML declaration are all preserved when converting between the two. The
only caveat is that it is possible to lose the order of differently named nodes at the
same level when they are grouped together into an array.</para>
</introduction>
<section>
<title>Conversion Rules</title>
<content>
<list class="bullet">
<listItem><para>Elements remain unchanged.</para></listItem>
<listItem><para>Attributes are prefixed with an @ and should be at the start of the object.</para></listItem>
<listItem><para>Single child text nodes are a value directly against an element, otherwise they are accessed via #text.</para></listItem>
<listItem><para>The XML declaration and processing instructions are prefixed with ?.</para></listItem>
<listItem><para>Charater data, comments, whitespace and significate whitespace nodes are accessed via
#cdata-section, #comment, #whitespace and #significate-whitespace respectively.</para></listItem>
<listItem><para>Multiple nodes with the same name at the same level are grouped together into an array.</para></listItem>
<listItem><para>Empty elements are null.</para></listItem>
</list>
<para>If the XML created from JSON doesn't match what you want then you will need to convert it manually.
The best approach to do this is to load your JSON into a LINQ to JSON object like JObject or JArray and then use LINQ to create
an XDocument. The opposite process, using LINQ with an XDocument to create a JObject or JArray, also works.
Find out more about using LINQ to JSON with LINQ <externalLink>
<linkText>here</linkText>
<linkUri>QueryingLINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>.</para>
<alert class="note">
<para>The version of Json.NET being used in your application will change what XML conversion methods are available.
SerializeXmlNode/DeserializeXmlNode are available when the framework supports XmlDocument,
SerializeXNode/DeserializeXNode are available when the framework supports XDocument.</para>
</alert>
</content>
</section>
<section>
<title>SerializeXmlNode</title>
<content>
<para>The JsonConvert has two helper methods for converting between JSON and XML. The first is
<codeEntityReference>Overload:Newtonsoft.Json.JsonConvert.SerializeXmlNode</codeEntityReference>.
This method takes an XmlNode and serializes it to JSON text.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConvertingJsonAndXmlTests.cs" region="SerializeXmlNode" title="Converting XML to JSON with SerializeXmlNode" />
<para>Because multiple nodes with a the same name at the same level are grouped together into an array
the convernsion process can produce different JSON depending on the number of nodes. For example if some
XML for a user has a single <codeInline>&lt;Role&gt;</codeInline> node then that role will be text against
a JSON <codeInline>"Role"</codeInline> property, but if the user has multiple <codeInline>&lt;Role&gt;</codeInline>
nodes then the role values will be placed in a JSON array.</para>
<para>To fix this situation a custom XML attribute can be added to force a JSON array to be created.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConvertingJsonAndXmlTests.cs" region="ForceJsonArray" title="Attribute to Force a JSON Array" />
</content>
</section>
<section>
<title>DeserializeXmlNode</title>
<content>
<para>The second helper method on JsonConvert is
<codeEntityReference>Overload:Newtonsoft.Json.JsonConvert.DeserializeXmlNode</codeEntityReference>.
This method takes JSON text and deserializes it into a XmlNode.</para>
<para>Because valid XML must have one root element the JSON passed to DeserializeXmlNode should
have one property in the root JSON object. If the root JSON object has multiple properties then
the overload that also takes an element name should be used. A root element with that name will
be inserted into the deserialized XmlNode.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ConvertingJsonAndXmlTests.cs" region="DeserializeXmlNode" title="Converting JSON to XML with DeserializeXmlNode" />
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.Converters.XmlNodeConverter</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.JsonConvert</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreatingLINQtoJSON" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>As well as parsing JSON from existing JSON strings, LINQ to JSON objects can be created from scratch to create new JSON structures.</para>
</introduction>
<section>
<title>Manually Creating JSON</title>
<content>
<para>Setting values and creating objects and arrays one at a time gives you
total control but it is more verbose than other options.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateNormal" title="Creating JSON" />
</content>
</section>
<section>
<title>Creating JSON with LINQ</title>
<content>
<para>Declaratively creating JSON objects using LINQ is a fast way to create JSON from collections of values.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateDeclaratively" title="Creating JSON Declaratively" />
</content>
</section>
<section>
<title>Creating JSON from an object</title>
<content>
<para>The last option is to create a JSON object from a non-JSON type using the
<codeEntityReference>Overload:Newtonsoft.Json.Linq.JObject.FromObject</codeEntityReference>
method. Internally FromObject will use the JsonSerializer to serialize the object to LINQ to JSON objects instead of text.</para>
<para>The example below is creating a JSON object from an anonymous object but any
.NET type can be used with FromObject to create JSON.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateFromObject" title="Creating JSON from an Object" />
</content>
</section>
<relatedTopics>
<externalLink>
<linkText>LINQ to JSON</linkText>
<linkUri>LINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
<codeEntityReference>Overload:Newtonsoft.Json.Linq.JObject.FromObject</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CustomCreationConverter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--
<summary>
<para>Optional summary abstract</para>
</summary>
-->
<introduction>
<para>The <codeEntityReference>T:Newtonsoft.Json.Converters.CustomCreationConverter`1</codeEntityReference>
is a JsonConverter that provides a way
to customize how an object is created during JSON deserialization. Once
the object has been created it will then have values populated onto it by
the serializer.</para>
</introduction>
<section>
<title>Example</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="CustomCreationConverterObject" title="CustomCreationConverter" />
<para>This is an extremely simple example. A more complicated scenario
could involve an object factory or service locator which resolves the
object at runtime.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="CustomCreationConverterExample" title="CustomCreationConverter Example" />
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.Converters.CustomCreationConverter`1</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DatesInJSON" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--
<summary>
<para>Optional summary abstract</para>
</summary>
-->
<introduction>
<para>DateTimes in JSON are hard.</para>
<para>The problem comes from the <externalLink>
<linkText>JSON spec</linkText>
<linkUri>http://www.ietf.org/rfc/rfc4627.txt</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink> itself: there is no literal
syntax for dates in JSON. The spec has objects, arrays, strings, integers
and floats, but it defines no standard for what a date looks like.</para>
</introduction>
<!-- Add one or more top-level section elements. These are collapsible.
If using <autoOutline />, add an address attribute to identify it
and specify a title so that it can be jumped to with a hyperlink. -->
<section>
<title>Dates and Json.NET</title>
<content>
<!-- Uncomment this to create a sub-section outline
<autoOutline /> -->
<para>The default format used by Json.NET is the <externalLink>
<linkText>ISO 8601 standard</linkText>
<linkUri>http://en.wikipedia.org/wiki/ISO_8601</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>: <codeInline>"2012-03-19T07:22Z"</codeInline>.</para>
<para>Prior to Json.NET 4.5 dates were written using the Microsoft
format: <codeInline>"\/Date(1198908717056)\/"</codeInline>. If you want to use this format, or
you want to maintain compatibility with Microsoft JSON serializers or
older versions of Json.NET then change the
<codeEntityReference>T:Newtonsoft.Json.DateFormatHandling</codeEntityReference>
setting to MicrosoftDateFormat.</para>
<para>Json.NET also has the <codeEntityReference>T:Newtonsoft.Json.DateTimeZoneHandling</codeEntityReference>
setting. This can be
used to convert DateTime's kind when serializing, e.g. set
DateTimeZoneHandling to Utc to serialize all DateTimes as UTC dates.</para>
</content>
</section>
<section>
<title>DateTime JsonConverters</title>
<content>
<!-- Uncomment this to create a sub-section outline
<autoOutline /> -->
<para>With no standard for dates in JSON, the number of possible
different formats when interoping with other systems is endless.
Fortunately Json.NET has a solution to deal with reading and writing
custom dates: JsonConverters. A JsonConverter is used to override how a
type is serialized.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="SerializingDatesInJson" title="DateTime JsonConverters Example" />
<para>Simply pass the JsonConverter you wish to use to the Json.NET
serializer.</para>
</content>
</section>
<section>
<title>JavaScriptDateTimeConverter</title>
<content>
<para>The JavaScriptDateTimeConverter class is one of the two DateTime
JsonConverters that come with Json.NET. This converter serializes a
DateTime as a <externalLink>
<linkText>JavaScript Date object</linkText>
<linkUri>http://msdn.microsoft.com/en-us/library/cd9w2te4.aspx</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>: <codeInline>new Date(1234656000000)</codeInline></para>
<para>Technically this is invalid JSON according to the spec but all
browsers, and some JSON frameworks, including Json.NET, support it.</para>
</content>
</section>
<section>
<title>IsoDateTimeConverter</title>
<content>
<alert class="note">
<para>From Json.NET 4.5 and onwards dates are written using the ISO 8601
format by default and using this converter is unnecessary.</para>
</alert>
<para>IsoDateTimeConverter seralizes a DateTime to an <externalLink>
<linkText>ISO 8601</linkText>
<linkUri>http://en.wikipedia.org/wiki/ISO_8601</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink> formatted
string: <codeInline>"2009-02-15T00:00:00Z"</codeInline></para>
<para>The IsoDateTimeConverter class has a property, DateTimeFormat, to
further customize the formatted string.</para>
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.DateFormatHandling</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.DateTimeZoneHandling</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Converters.JavaScriptDateTimeConverter</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Converters.IsoDateTimeConverter</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="Introduction" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--
<summary>
<para>Optional summary abstract</para>
</summary>
-->
<introduction>
<para>Json.NET is a popular high-performance JSON framework for .NET</para>
</introduction>
<!-- Optional procedures followed by optional code example but must have
at least one procedure or code example -->
<section>
<title>Benefits and Features</title>
<content>
<list class="bullet">
<listItem>
<para>Flexible JSON serializer for converting between .NET objects and JSON</para>
</listItem>
<listItem>
<para>LINQ to JSON for manually reading and writing JSON </para>
</listItem>
<listItem>
<para>High performance, faster than .NET's built-in JSON serializers</para>
</listItem>
<listItem>
<para>Write indented, easy to read JSON</para>
</listItem>
<listItem>
<para>Convert JSON to and from XML</para>
</listItem>
<listItem>
<para>Supports .NET 2, .NET 3.5, .NET 4, .NET 4.5, Silverlight, Windows Phone and Windows 8 Store</para>
</listItem>
</list>
<para>The JSON serializer in Json.NET is a good choice when the JSON you are reading or writing maps closely to a .NET class.</para>
<para>LINQ to JSON is good for situations where you are only interested in
getting values from JSON, you don't have a class to serialize or deserialize to,
or the JSON is radically different from your class and you need to manually read
and write from your objects.</para>
</content>
</section>
<section>
<title>Getting Started</title>
<content>
<list class="bullet">
<listItem><para><externalLink>
<linkText>Serializing and Deserializing JSON</linkText>
<linkUri>SerializingJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink></para></listItem>
<listItem><para><externalLink>
<linkText>LINQ to JSON</linkText>
<linkUri>LINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink></para></listItem>
<listItem><para><externalLink>
<linkText>Samples</linkText>
<linkUri>Samples.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink></para></listItem>
</list>
</content>
</section>
<section>
<title>History</title>
<content><para>Json.NET grew out of projects I was working on in late 2005 involving JavaScript,
AJAX and .NET. At the time there were no libraries for working with JavaScript in
.NET so I made my own.</para>
<para>Starting out as a couple of static methods for escaping JavaScript strings, Json.NET
evolved as features were added. To add support for reading JSON a major refactor
was required and Json.NET will split into the three major classes it still uses
today, JsonReader, JsonWriter and JsonSerializer.</para>
<para>Json.NET was first released in June 2006. Since then Json.NET has been downloaded
hundreds of thousands of times by developers around the world. It is used in many major open
source projects including <externalLink>
<linkText>Mono</linkText>
<linkUri>http://www.mono-project.com/</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>,
an open source implementation
of the .NET framework; <externalLink>
<linkText>RavenDB</linkText>
<linkUri>http://ravendb.net/</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>,
a JSON based documentat database; <externalLink>
<linkText>ASP.NET SignalR</linkText>
<linkUri>http://signalr.net/</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>,
an async library for building real-time, multi-user interactive web applications; and <externalLink>
<linkText>ASP.NET Web API</linkText>
<linkUri>http://www.asp.net/web-api</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>,
Microsoft's HTTP service framework.</para>
</content>
</section>
<section>
<title>Donate</title>
<content><para>Json.NET is a personal open source project. Started in 2006, I have put hundreds of hours adding, refining and tuning Json.NET with the goal to make it not just the best JSON serializer for .NET but the best serializer for any computer language. I need your
help to achieve this.</para>
<markup>
<p>
<a href="http://www.pledgie.com/campaigns/18941" target="_blank"><img src="http://www.pledgie.com/campaigns/18941.png?skin_name=chrome" alt="Click here to lend your support to: Json.NET and make a donation at www.pledgie.com !" border="0" /></a>
</p>
</markup>
</content>
</section>
<relatedTopics>
<externalLink>
<linkText>Serializing and Deserializing JSON</linkText>
<linkUri>SerializingJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
<externalLink>
<linkText>LINQ to JSON</linkText>
<linkUri>LINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
<externalLink>
<linkText>Samples</linkText>
<linkUri>Samples.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,454 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonNetVsDotNetSerializers" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Json.NET offers many features not found in the JavaScriptSerializer and DataContractSerializer that come with .NET.</para>
</introduction>
<section>
<title>Feature Comparison</title>
<content>
<table>
<tableHeader>
<row>
<entry><para></para></entry>
<entry><para>Json.NET</para></entry>
<entry><para>DataContractJsonSerializer</para></entry>
<entry><para>JavaScriptSerializer</para></entry>
</row>
</tableHeader>
<row>
<entry><para>Supports JSON</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports BSON</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports JSON Schema</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports .NET 2.0</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports .NET 3.5</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports .NET 4.0</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports Silverlight</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports Windows Phone</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports WinRT</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Open Source</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>MIT License</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>LINQ to JSON</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Thread Safe</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>XPath-like JSON query syntax</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Indented JSON support</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>
<externalLink>
<linkText>Efficient dictionary serialization</linkText>
<linkUri>http://stackoverflow.com/questions/1207731/how-can-i-deserialize-json-to-a-simple-dictionarystring-string-in-asp-net</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>
</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>
<externalLink>
<linkText>Nonsensical dictionary serialization</linkText>
<linkUri>http://stackoverflow.com/questions/4559991/any-way-to-make-datacontractjsonserializer-serialize-dictionaries-properly</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>
</para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Deserializes IList, IEnumerable, ICollection, IDictionary properties</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serializes circular references</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports serializing objects by reference</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Deserializes polymorphic properties and collections</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serializes and deserializes multidimensional arrays</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports including type names with JSON</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Globally customize serialization process</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports excluding null values when serializing</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports SerializationBinder</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Conditional property serialization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Includes line number information in errors</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Converts XML to JSON and JSON to XML</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>JSON Schema validation</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>JSON Schema generation from .NET types</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Camel case JSON property names</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Non-default constructors support</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serialization error handling</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports populating an existing object</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Efficiently serializes byte arrays as base64 text</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Handles NaN, Infinity, -Infinity and undefined</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Handles JavaScript constructors</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serializes .NET 4.0 dynamic objects</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serializes ISerializable objects</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports serializing enums to their text name</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>JSON recursion limit support</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Attribute property name customization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Attribute property order customization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Attribute property required customization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports ISO8601 dates</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports JavaScript constructor dates</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports Microsoft AJAX dates</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Unquoted property names support</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Raw JSON support</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports reading and writing comments</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serializes anonymous types</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Deserializes anonymous types</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Opt-in mode serialization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Opt-out mode serialization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Field (Serializable) mode serialization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Efficiently stream reading and writing JSON</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Single or double quote JSON content</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports overriding a type&apos;s serialization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports OnDeserialized, OnSerializing, OnSerialized and OnDeserializing attributes</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Supports serializing private properties</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>DataMember attribute support</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>MetdataType attribute support</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>DefaultValue attribute support</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serializes DataSets and DataTables</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serailizes Entity Framework</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Serializes nHibernate</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
<row>
<entry><para>Case-insensitive property deserialization</para></entry>
<entry><para><markup><img src="../tick.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
<entry><para><markup><img src="../cross.png" /></markup></para></entry>
</row>
</table>
</content>
</section>
<section>
<title>Benchmarks</title>
<content>
<mediaLink>
<image class="image" xlink:href="performance" mimeType="image/png" width="643" height="345" />
<summary>Json.NET Performance</summary>
</mediaLink>
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonNetVsWindowsDataJson" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Windows 8 introduces a new way to work with JSON via the <externalLink>
<linkText>Windows.Data.Json</linkText>
<linkUri>http://msdn.microsoft.com/en-us/library/windows/apps/xaml/br240639.aspx</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink> namespace. Similar to LINQ to JSON in Json.NET
it defines classes that can be used to parse values, strings, objects, and arrays from
JSON text or serialize value types into JSON text.</para>
<para>Below is a comparison of Json.NET&apos;s LINQ to JSON to Window 8&apos;s Windows.Data.Json.</para>
</introduction>
<section>
<title>Exclusive Json.NET Features</title>
<content>
<list class="bullet">
<listItem>
<para>
Runs on .NET 2, .NET 3, .NET 4, Silverlight and Windows Phone 7
</para>
</listItem>
<listItem>
<para>
Dynamic programming
</para>
</listItem>
<listItem>
<para>
Write indented JSON
</para>
</listItem>
<listItem>
<para>
Customize reading and writing JSON with JsonConverters
</para>
</listItem>
<listItem>
<para>
Read and write ISO8601 dates
</para>
</listItem>
<listItem>
<para>
Better LINQ support
</para>
</listItem>
</list>
</content>
</section>
<section>
<title>Creating JSON</title>
<content>
<para>The big difference between the two libraries when creating JSON is Windows.Data.Json requires
string/integer/double values to be explicitly converted to JsonValue objects.</para>
<para>Note that there is a weird limitation to creating JSON with Windows.Data.Json: it doesn&apos;t
allow you to set properties to null or put null values in an array.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonNetVsWindowsDataJsonTests.cs" region="CreatingJSON" title="Creating JSON with Json.NET and Windows.Data.Json" />
</content>
</section>
<section>
<title>Querying JSON</title>
<content>
<para>Windows.Data.Json requires a value to be cast to its exact type with the GetObject/GetArray methods
before it can be used, making Windows.Data.Json&apos;s code verbose compared to LINQ to JSON.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonNetVsWindowsDataJsonTests.cs" region="QueryingJSON" title="Querying JSON with Json.NET and Windows.Data.Json" />
</content>
</section>
<section>
<title>Benchmarks</title>
<content>
<para>Json.NET is slightly slower at writing JSON than Windows.Data.Json but considerably faster at parsing JSON.</para>
<mediaLink>
<image class="image" xlink:href="jsonnetwindowsdatajson" mimeType="image/png" width="592" height="356" />
<summary>Json.NET and Windows.Data.Json Performance</summary>
</mediaLink>
</content>
</section>
<section>
<title>Converting Between LINQ to JSON and Windows.Data.Json</title>
<content>
<para>Json.NET supports converting between the types of the two libraries.
This feature is useful if you are working with another API that uses Windows.Data.Json types but you want to use Json.NET inside your own code.</para>
<para>Use <codeEntityReference>Overload:Newtonsoft.Json.Linq.JToken.FromObject</codeEntityReference> to convert a Windows.Data.Json
value to LINQ to JSON and use <codeEntityReference>Overload:Newtonsoft.Json.Linq.JToken.ToObject</codeEntityReference> to convert LINQ to JSON to Windows.Data.Json.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonNetVsWindowsDataJsonTests.cs" region="Converting" title="Converting between Json.NET and Windows.Data.Json" />
</content>
</section>
<relatedTopics>
<codeEntityReference>N:Newtonsoft.Json.Linq</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonSchema" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Json.NET supports the JSON Schema standard via the <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.JsonValidatingReader</codeEntityReference> classes. It sits under
the <codeEntityReference>N:Newtonsoft.Json.Schema</codeEntityReference> namespace.</para>
<para>JSON Schema is used to validate the structure and
data types of a piece of JSON, similar to XML Schema for XML. Read more about JSON Schema at
<externalLink>
<linkText>json-schema.org</linkText>
<linkUri>http://json-schema.org/</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink></para>
</introduction>
<alert class="caution">
<para>
The JSON Schema standard isn't final.
Json.NET implements
<externalLink>
<linkText>JSON Schema Draft 3</linkText>
<linkUri>http://tools.ietf.org/search/draft-zyp-json-schema-03/</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.
There will be breaking changes to some parts of Json.NET's JSON Schema API when it is updated to implement newer drafts of JSON Schema.
</para>
</alert>
<!-- Optional procedures followed by optional code example but must have
at least one procedure or code example -->
<section>
<title>Validating with JSON Schema</title>
<content>
<para>The simplest way to check if JSON is valid is to load the JSON into a JObject or JArray and then
use the <codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema)</codeEntityReference>
method with the JSON Schema.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="IsValidBasic" title="Validate JSON with IsValid" />
<para>To get validation error messages use the
<codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema,System.Collections.Generic.IList{System.String}@)</codeEntityReference>
or
<codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.Validate(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema,Newtonsoft.Json.Schema.ValidationEventHandler)</codeEntityReference>
overloads.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="IsValidMessages" title="Validate JSON with IsValid" />
<para>Internally IsValid uses <codeEntityReference>T:Newtonsoft.Json.JsonValidatingReader</codeEntityReference>
to perform the JSON Schema validation. To skip the overhead of loading JSON into a JObject/JArray, validating
the JSON and then deserializing the JSON into a class, JsonValidatingReader can be used with JsonSerializer to validate JSON while the object is being deserialized.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="JsonValidatingReader" title="Validate JSON with JsonValidatingReader" />
</content>
</section>
<section>
<title>Creating JSON Schemas</title>
<content>
<para>The simplest way to get a <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference> object is to load it from a string or a file.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="LoadJsonSchema" title="Creating JSON Schemas from strings or files" />
<para>It is also possible to create JsonSchema objects in code.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\JsonSchemaTests.cs" region="ManuallyCreateJsonSchema" title="Create new JSON Schemas in code" />
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.JsonValidatingReader</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="LINQtoJSON" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>LINQ to JSON is an API for working with JSON objects.
It has been designed with LINQ in mind to enable to quick querying
and creation of JSON objects. LINQ to JSON sits under the
<codeEntityReference>N:Newtonsoft.Json.Linq</codeEntityReference>
namespace.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonBasic" title="Using LINQ for JSON" />
</introduction>
<section>
<title>Topics</title>
<content>
<para>Select a topic below for more information:</para>
<list class="bullet">
<listItem>
<para>
<externalLink>
<linkText>Parsing JSON</linkText>
<linkUri>ParsingLINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
</para>
</listItem>
<listItem>
<para>
<externalLink>
<linkText>Creating JSON</linkText>
<linkUri>CreatingLINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
</para>
</listItem>
<listItem>
<para>
<externalLink>
<linkText>Querying JSON with LINQ</linkText>
<linkUri>QueryingLINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
</para>
</listItem>
<listItem>
<para>
<externalLink>
<linkText>Querying JSON with SelectToken</linkText>
<linkUri>SelectToken.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
</para>
</listItem>
</list>
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Linq.JArray</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Linq.JValue</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ParsingLINQtoJSON" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>LINQ to JSON has methods available for parsing JSON from a string or loading JSON directly from a file.</para>
</introduction>
<section>
<title>Parsing JSON text</title>
<content>
<para>JSON values can be read from a string using
<codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Parse(System.String)</codeEntityReference>.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateParse" title="Parsing a JSON Object from text" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonCreateParseArray" title="Parsing a JSON Array from text" />
</content>
</section>
<section>
<title>Loading JSON from a file</title>
<content>
<para>JSON can also be loaded directly from a file using <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.ReadFrom(Newtonsoft.Json.JsonReader)</codeEntityReference>.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonReadObject" title="Reading JSON from a file" />
</content>
</section>
<relatedTopics>
<externalLink>
<linkText>LINQ to JSON</linkText>
<linkUri>LINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
<codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Parse(System.String)</codeEntityReference>
<codeEntityReference>M:Newtonsoft.Json.Linq.JToken.ReadFrom(Newtonsoft.Json.JsonReader)</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="Performance" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Out of the box Json.NET is faster than DataContractJsonSerializer and JavaScriptSerializer.
Here are some tips to make it go even faster.</para>
</introduction>
<section>
<title>Optimize Memory Usage</title>
<content>
<para>To keep an application consistantly fast it is important to minimize the
amount of time the .NET framework spends performing <externalLink>
<linkText>garbage collection</linkText>
<linkUri>http://msdn.microsoft.com/en-us/library/ms973837.aspx</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.
Allocating too many objects, or allocating very large objects can slow down or even
halt an application while garbage collection is in progress.
</para>
<para>To minimize memory usage and the number of objects allocated Json.NET supports
serializing and deserializing directly to a stream. Reading or writing JSON a piece at a time instead of having
the entire JSON string loaded into memory is especially important when working with JSON
documents greater than 85kb in size to avoid the JSON string ending up in the <externalLink>
<linkText>large object heap</linkText>
<linkUri>http://msdn.microsoft.com/en-us/magazine/cc534993.aspx</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeString" title="Deserialize String" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="DeserializeStream" title="Deserialize Stream" />
</content>
</section>
<section>
<title>JsonConverters</title>
<content>
<para>Passing a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference> to SerializeObject or DeserializeObject provides a simple way to completely
change how an object is serialized. There is however a small overhead; the CanConvert method is called for every
value to check whether serialization should be handled by that JsonConverter.</para>
<para>There are a couple of ways to continue to use JsonConverters without any overhead. The simplest way
is to specify the JsonConverter using the <codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>. This attribute tells the serializer
to always use that converter when serializing and deserializing the type, without the check.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterAttribute" title="Use JsonConverter with JsonConverterAttribute" />
<para>If the class you want to convert isn't your own and you're unable to use an attribute a JsonConverter can still be used by
creating your own <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="JsonConverterContractResolver" title="Use JsonConverter with IContractResolver" />
<para>The IContractResolver in the example above will set all DateTimes to use the JavaScriptDateConverter.</para>
</content>
</section>
<section>
<title>Manually Serialize</title>
<content>
<para>The absolute fastest way to read and write JSON is to use JsonTextReader/JsonTextWriter directly to manually serialize types.
Using a reader or writer directly skips any of the overhead from a serializer such as reflection.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\PerformanceTests.cs" region="ReaderWriter" title="Manually serialize using JsonTextWriter" />
<para>If performance is important and you don't mind more code to get it then this is your best choice. Read more about using JsonReader/JsonWriter here:
<externalLink>
<linkText>Basic Reading and Writing JSON</linkText>
<linkUri>ReadingWritingJSON.aml</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
</para>
</content>
</section>
<section>
<title>Benchmarks</title>
<content>
<mediaLink>
<image class="image" xlink:href="performance" mimeType="image/png" width="643" height="345" />
<summary>Json.NET Performance</summary>
</mediaLink>
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.JsonTextWriter</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.JsonTextReader</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="PreserveObjectReferences" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--
<summary>
<para>Optional summary abstract</para>
</summary>
-->
<introduction>
<para>By default Json.NET will serialize all objects it encounters by value.
If a list contains two Person references, and both references point to the
same object then the JsonSerializer will write out all the names and values
for each reference.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="PreservingObjectReferencesOff" title="Preserve Object References Off" />
<para>In most cases this is the desired result but in certain scenarios
writing the second item in the list as a reference to the first is a better
solution. If the above JSON was deserialized now then the returned list would
contain two completely separate Person objects with the same values. Writing
references by value will also cause problems on objects where a circular
reference occurs.</para>
</introduction>
<!-- Add one or more top-level section elements. These are collapsible.
If using <autoOutline />, add an address attribute to identify it
and specify a title so that it can be jumped to with a hyperlink. -->
<section>
<title>PreserveReferencesHandling</title>
<content>
<para>Setting <codeEntityReference>T:Newtonsoft.Json.PreserveReferencesHandling</codeEntityReference> will track object references
when serializing and deserializing JSON.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="PreservingObjectReferencesOn" title="Preserve Object References On" />
<para>The first Person in the list is serizlied with the addition of an
object Id. The second Person in JSON is now only a reference to the first.</para>
<para>With PreserveReferencesHandling on now only one Person object is created
on deserialization and the list contains two references to it, mirroring
what we started with.</para>
<alert class="note">
<para>References cannot be preserved when a value is set via a non-default constructor.
With a non-default constructor child values must be created before the parent value so they can be passed into
the constructor, making tracking reference impossible.
<codeEntityReference>T:System.Runtime.Serialization.ISerializable</codeEntityReference> types are an example
of a class whose values are populated with a non-default constructor and won't work with PreserveReferencesHandling.</para>
</alert>
</content>
</section>
<section>
<title>IsReference</title>
<content>
<para>The PreserveReferencesHandling setting on the JsonSerializer will
change how all objects are serialized and deserialized. For fine grain
control over which objects and members should be serialized as a
reference there is the IsReference property on the JsonObjectAttribute,
JsonArrayAttribute and JsonPropertyAttribute.</para>
<para>Setting IsReference on JsonObjectAttribute or JsonArrayAttribute to
true will mean the JsonSerializer will always serialize the type the
attribute is against as a reference. Setting IsReference on the
JsonPropertyAttribute to true will serialize only that property as a
reference.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="PreservingObjectReferencesAttribute" title="IsReference" />
</content>
</section>
<section>
<title>IReferenceResolver</title>
<content>
<para>To customize how references are generated and resolved the
<codeEntityReference>T:Newtonsoft.Json.Serialization.IReferenceResolver</codeEntityReference>
interface is available to inherit from and use with
the JsonSerializer.</para>
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.PreserveReferencesHandling</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="QueryingLINQtoJSON" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<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
on an object or index in a collection, while <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Children</codeEntityReference> lets you get ranges
of data as <codeInline>IEnumerable&lt;JToken&gt;</codeInline> to then query using LINQ.</para>
</introduction>
<section>
<title>Getting values by Property Name or Collection Index</title>
<content>
<!-- Uncomment this to create a sub-section outline
<autoOutline /> -->
<para>The simplest way to get a value from LINQ to JSON is to use the
<codeEntityReference>P:Newtonsoft.Json.Linq.JToken.Item(System.Object)</codeEntityReference> index on
JObject/JArray and then cast the returned <codeEntityReference>T:Newtonsoft.Json.Linq.JValue</codeEntityReference> to the type you want.
</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonSimpleQuerying" title="Getting JSON Values" />
</content>
</section>
<section>
<title>Querying with LINQ</title>
<content>
<para>JObject/JArray can also be queried using LINQ. <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Children</codeEntityReference>
returns the children values of a JObject/JArray
as an <codeInline>IEnumerable&lt;JToken&gt;</codeInline> that can then be queried with the standard Where/OrderBy/Select LINQ operators.</para>
<alert class="note">
<para><codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Children</codeEntityReference> returns all the children of a token. If it is a
JObject it will return a collection of properties to work with and if
it is a JArray you will get a collection of the array's values.</para>
</alert>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonQuerying" title="Querying JSON" />
<para>LINQ to JSON can also be used to manually convert JSON to a .NET object.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonDeserializeObject" title="Deserializing Using LINQ Objects" />
<para>Manually serializing and deserializing between .NET objects is useful when you are
working with JSON that doesn't closely match your .NET objects.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\LinqToJsonTests.cs" region="LinqToJsonDeserializeExample" title="Deserializing Using LINQ Example" />
</content>
</section>
<relatedTopics>
<externalLink>
<linkText>LINQ to JSON</linkText>
<linkUri>LINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
<codeEntityReference>P:Newtonsoft.Json.Linq.JToken.Item(System.Object)</codeEntityReference>
<codeEntityReference>M:Newtonsoft.Json.Linq.JToken.Children</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ReadingWritingJSON" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>To manually read and write JSON Json.NET provides the
<codeEntityReference>T:Newtonsoft.Json.JsonReader</codeEntityReference>
and
<codeEntityReference>T:Newtonsoft.Json.JsonWriter</codeEntityReference> classes.</para>
</introduction>
<section>
<title>JsonTextReader and JsonTextWriter</title>
<content>
<alert class="note">
<para>JsonReader and JsonWriter are low level classes and used internally by Json.NET.
To quickly work with JSON either the serializer -
<externalLink>
<linkText>Serializing and Deserializing JSON</linkText>
<linkUri>SerializingJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink>
or using <externalLink>
<linkText>LINQ to JSON</linkText>
<linkUri>LINQtoJSON.htm</linkUri>
<linkTarget>_self</linkTarget>
</externalLink> is recommended.
</para>
</alert>
<para><codeEntityReference>T:Newtonsoft.Json.JsonTextReader</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.JsonTextWriter</codeEntityReference>
are used to read and write JSON text.
The JsonTextWriter has a number of settings on it to control how JSON is formatted
when it is written. These options include formatting, indention character, indent
count and quote character.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ReadingAndWritingJsonTests.cs" region="ReadingAndWritingJsonText" title="Writing JSON with JsonTextWriter" />
<para>JsonTextReader has settings on it for reading different date formats and time zones, and
the culture used when reading text values.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ReadingAndWritingJsonTests.cs" region="ReadingJsonText" title="Reading JSON with JsonTextReader" />
</content>
</section>
<section>
<title>JTokenReader and JTokenWriter</title>
<content>
<para><codeEntityReference>T:Newtonsoft.Json.Linq.JTokenReader</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.Linq.JTokenWriter</codeEntityReference>
read and write LINQ to JSON objects. They are located in the
<codeEntityReference>N:Newtonsoft.Json.Linq</codeEntityReference>
namespace. These objects allow you to use LINQ to JSON objects with objects that
read and write JSON such as the JsonSerializer. For example you can deserialize
from a LINQ to JSON object into a regular .NET object and vice versa.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\ReadingAndWritingJsonTests.cs" region="ReadingAndWritingJsonLinq" title="Deserializing with JTokenReader" />
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.JsonReader</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.JsonWriter</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Linq.JTokenReader</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Linq.JTokenWriter</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Bson.BsonReader</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.Bson.BsonWriter</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ReducingSerializedJSONSize" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<!--
<summary>
<para>Optional summary abstract</para>
</summary>
-->
<introduction>
<!-- Uncomment this to generate an outline of the section and sub-section
titles. Specify a numeric value as the inner text to limit it to
a specific number of sub-topics when creating the outline. Specify
zero (0) to limit it to top-level sections only. -->
<!-- <autoOutline /> -->
<para>One of the common problems encountered when serializing .NET objects to
JSON is that the JSON ends up containing a lot of unwanted properties and values.
This can be especially important when returning JSON to the client. More JSON
means more bandwidth and a slower website.</para>
<para>To solve the issue of unwanted JSON Json.NET has a range of built in
options to fine tune what gets written from a serialized object.</para>
</introduction>
<!-- Add one or more top-level section elements. These are collapsible.
If using <autoOutline />, add an address attribute to identify it
and specify a title so that it can be jumped to with a hyperlink. -->
<section>
<title>JsonIgnoreAttribute and DataMemberAttribute</title>
<content>
<!-- Uncomment this to create a sub-section outline
<autoOutline /> -->
<para>By default Json.NET will include all of a classes public properties and fields
in the JSON it creates. Adding the
<codeEntityReference>T:Newtonsoft.Json.JsonIgnoreAttribute</codeEntityReference>
to a property tells the serializer to always skip writing it to the JSON result.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeOptOut" title="Opt-out Serialization Example" />
<para>If a class has many properties and you only want to serialize a small subset
of them then adding JsonIgnore to all the others will be tedious and error prone.
The way to tackle this scenario is to add the
<codeEntityReference>T:System.Runtime.Serialization.DataContractAttribute</codeEntityReference>
to the class and
<codeEntityReference>T:System.Runtime.Serialization.DataMemberAttribute</codeEntityReference>
to the properties to serialize. This is opt-in
serialization, only the properties you mark up with be serialized, compared to
opt-out serialization using JsonIgnoreAttribute.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeOptIn" title="Opt-in Serialization Example" />
</content>
</section>
<section>
<title>Formatting</title>
<content>
<para>JSON written by the serializer with an option of
<codeEntityReference>T:Newtonsoft.Json.Formatting</codeEntityReference>
set to Indented produces
nicely formatted, easy to read JSON that is great for readability when you are
developing. Formatting.None on the other hand keeps the JSON result small, skipping
all unnecessary spaces and line breaks to produce the most compact and efficient
JSON possible.</para>
</content>
</section>
<section>
<title>NullValueHandling</title>
<content>
<para><codeEntityReference>T:Newtonsoft.Json.NullValueHandling</codeEntityReference>
is an option on the JsonSerializer and controls how the
serializer handles properties with a null value. By setting a value of
NullValueHandling.Ignore the JsonSerializer skips writing any properties that have
a value of null.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeNullValueHandlingObject" title="NullValueHandling Class" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeNullValueHandlingExample" title="NullValueHandling Ignore Example" />
<para>NullValueHandling can also be customized on individual properties
using the a
<codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference>.
The JsonPropertyAttribute value of
NullValueHandling will override the setting on the JsonSerializer for that
property.</para>
</content>
</section>
<section>
<title>DefaultValueHandling</title>
<content>
<para><codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference>
is an option on the JsonSerializer and controls how the serializer handles
properties with a default value. Setting a value of DefaultValueHandling.Ignore
will make the JsonSerializer skip writing any properties that have a default
value to the JSON result. For object references this will be null. For value
types like int and DateTime the serializer will skip the default uninitialized
value for that value type.</para>
<para>Json.NET also allows you to customize what the default value of an individual
property is using the
<codeEntityReference>T:System.ComponentModel.DefaultValueAttribute</codeEntityReference>.
For example if a string property called
Department always returns an empty string in its default state and you didn't want
that empty string in your JSON then placing the DefaultValueAttribute on Department
with that value will mean Department is no longer written to JSON unless it has a
value.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeDefaultValueHandlingObject" title="DefaultValueHandling Class" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeDefaultValueHandlingExample" title="DefaultValueHandling Ignore Example" />
<para>DefaultValueHandling can also be customized on individual properties using
the a
<codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference>.
The JsonPropertyAttribute value of DefaultValueHandling
will override the setting on the JsonSerializer for that property.</para>
</content>
</section>
<section>
<title>IContractResolver</title>
<content>
<para>For more flexibility the
<codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
provides an interface to customize
almost every aspect of how a .NET object gets serialized to JSON, including changing
serialization behavior at runtime.</para>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeContractResolverObject" title="IContractResolver Class" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\SerializationTests.cs" region="ReducingSerializedJsonSizeContractResolverExample" title="IContractResolver Example" />
</content>
</section>
<relatedTopics>
<codeEntityReference>T:Newtonsoft.Json.Formatting</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.JsonIgnoreAttribute</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference>
<codeEntityReference>T:Newtonsoft.Json.NullValueHandling</codeEntityReference>
</relatedTopics>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeFromBson" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample deserializes BSON to an object.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Bson\DeserializeFromBson.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Bson\DeserializeFromBson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeFromBsonCollection" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample sets <codeEntityReference>P:Newtonsoft.Json.Bson.BsonReader.ReadRootValueAsArray</codeEntityReference>
to <codeInline>true</codeInline> so the root BSON value is correctly read
as an array instead of an object and deserializes BSON to a collection.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Bson\DeserializeFromBsonCollection.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Bson\DeserializeFromBsonCollection.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeToBson" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample serializes an object to BSON.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Bson\SerializeToBson.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Bson\SerializeToBson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ReadJsonWithJsonTextReader" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample reads JSON using the <codeEntityReference>T:Newtonsoft.Json.JsonTextReader</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Json\ReadJsonWithJsonTextReader.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="WriteJsonWithJsonTextWriter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample writes JSON using the <codeEntityReference>T:Newtonsoft.Json.JsonTextWriter</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Json\WriteJsonWithJsonTextWriter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="Clone" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample recursively clones a <codeEntityReference>T:Newtonsoft.Json.Linq.JToken</codeEntityReference>
and all its children using <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.DeepClone</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\Clone.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateJsonAnonymousObject" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates a <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
from an anonymous type.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateJsonAnonymousObject.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateJsonAnonymousObject.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateJsonCollectionInitializer" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.Linq.JArray</codeEntityReference> instances using
the C# collection initializer syntax.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateJsonCollectionInitializer.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateJsonDeclaratively" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.Linq.JArray</codeEntityReference> instances declaratively
using LINQ.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateJsonDeclaratively.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateJsonDeclaratively.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateJsonDynamic" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.Linq.JArray</codeEntityReference> instances using
the C# dynamic functionality.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateJsonDynamic.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateJsonJTokenWriter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.Linq.JArray</codeEntityReference> instances using
a <codeEntityReference>T:Newtonsoft.Json.Linq.JTokenWriter</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateJsonJTokenWriter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateJsonManually" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.Linq.JArray</codeEntityReference> instances one at a time
programatically.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateJsonManually.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateReader" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates a <codeEntityReference>T:Newtonsoft.Json.Linq.JTokenReader</codeEntityReference>
from a <codeEntityReference>T:Newtonsoft.Json.Linq.JToken</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateReader.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateWriter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates a <codeEntityReference>T:Newtonsoft.Json.Linq.JTokenWriter</codeEntityReference>
from a <codeEntityReference>T:Newtonsoft.Json.Linq.JToken</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\CreateWriter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeepEquals" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample compares <codeEntityReference>T:Newtonsoft.Json.Linq.JToken</codeEntityReference>
instances using <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.DeepEquals(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Linq.JToken)</codeEntityReference>,
comparing the token and all child tokens.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\DeepEquals.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeWithLinq" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample uses LINQ to JSON to manually convert JSON to a .NET type.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\DeserializeWithLinq.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\DeserializeWithLinq.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="FromObject" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample converts .NET values to LINQ to JSON using
<codeEntityReference qualifyHint="true">M:Newtonsoft.Json.Linq.JToken.FromObject(System.Object)</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\FromObject.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\FromObject.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JObjectProperties" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample gets an object's <codeEntityReference>T:Newtonsoft.Json.Linq.JProperty</codeEntityReference>
collection using <codeEntityReference>M:Newtonsoft.Json.Linq.JObject.Properties</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\JObjectProperties.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JValueCast" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample casts <codeEntityReference>T:Newtonsoft.Json.Linq.JValue</codeEntityReference>
instances to .NET values.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\JValueCast.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JValueValue" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample gets <codeEntityReference>T:Newtonsoft.Json.Linq.JValue</codeEntityReference>
internal values using <codeEntityReference>P:Newtonsoft.Json.Linq.JValue.Value</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\JValueValue.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ModifyJson" 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, modifies <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
and <codeEntityReference>T:Newtonsoft.Json.Linq.JArray</codeEntityReference>
instances and then writes the JSON back out again.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ModifyJson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ParseJsonAny" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample parses JSON using
<codeEntityReference qualifyHint="true">M:Newtonsoft.Json.Linq.JToken.Parse(System.String)</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ParseJsonAny.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ParseJsonArray" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample parses a JSON array using
<codeEntityReference qualifyHint="true">M:Newtonsoft.Json.Linq.JArray.Parse(System.String)</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ParseJsonArray.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ParseJsonObject" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample parses a JSON object using
<codeEntityReference qualifyHint="true">M:Newtonsoft.Json.Linq.JObject.Parse(System.String)</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ParseJsonObject.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="QueryJson" 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 and then queries values from it using
<codeEntityReference>P:Newtonsoft.Json.Linq.JToken.Item(System.Object)</codeEntityReference>
indexer and then casts the returned tokens to .NET values.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\QueryJson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="QueryJsonDynamic" 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 and then queries values from it using
C# dynamic functionality.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\QueryJsonDynamic.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="QueryJsonLinq" 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 and then queries values from it using LINQ operators.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\QueryJsonLinq.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="QueryJsonSelectToken" 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 and then queries values from it 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\QueryJsonSelectToken.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="QueryJsonSelectTokenWithLinq" 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 and then queries values from it using a combination of <codeEntityReference>M:Newtonsoft.Json.Linq.JToken.SelectToken(System.String)</codeEntityReference>
and LINQ operators.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\QueryJsonSelectTokenWithLinq.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ReadJTokenFromBson" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample reads a <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
from BSON using <codeEntityReference>T:Newtonsoft.Json.Bson.BsonReader</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ReadJTokenFromBson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ReadJson" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample reads JSON from a file into a <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ReadJson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SerializeWithLinq" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample uses LINQ to JSON to manually convert a .NET type to JSON.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\SerializeWithLinq.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\SerializeWithLinq.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ToObjectComplex" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample converts LINQ to JSON objects to .NET types using
<codeEntityReference>M:Newtonsoft.Json.Linq.JToken.ToObject``1</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ToObjectComplex.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ToObjectGeneric" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample converts LINQ to JSON objects to .NET types using
<codeEntityReference>M:Newtonsoft.Json.Linq.JToken.ToObject``1</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ToObjectGeneric.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ToObjectType" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample converts LINQ to JSON objects to .NET types using
<codeEntityReference>M:Newtonsoft.Json.Linq.JToken.ToObject(System.Type)</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ToObjectType.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ToString" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample converts LINQ to JSON objects to JSON.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ToString.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="ToStringJsonConverter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample uses a <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
to customize converting LINQ to JSON objects to JSON.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\ToStringJsonConverter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="WriteJTokenToBson" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample writes a <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
to BSON using <codeEntityReference>T:Newtonsoft.Json.Bson.BsonWriter</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\WriteJTokenToBson.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="WriteToJsonFile" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample writes LINQ to JSON objects to a file.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Linq\WriteToJsonFile.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="Samples" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>Over 100 code samples covering Json.NET's most commonly used functionality.</para>
</introduction>
<section>
<title>Samples</title>
<content>
<list class="bullet">
<listItem>
<para><legacyBold>Serializing JSON</legacyBold> - Serializing and deserializing JSON, serializer settings and serialization attributes</para>
</listItem>
<listItem>
<para><legacyBold>LINQ to JSON</legacyBold> - Parsing, querying, modifying and writing JSON</para>
</listItem>
<listItem>
<para><legacyBold>JSON Schema</legacyBold> - Loading schemas and validating JSON</para>
</listItem>
<listItem>
<para><legacyBold>Converting XML</legacyBold> - Converting JSON to XML and XML to JSON</para>
</listItem>
<listItem>
<para><legacyBold>BSON</legacyBold> - Serializing and deserializing BSON</para>
</listItem>
<listItem>
<para><legacyBold>Reading and Writing JSON</legacyBold> - Reading JSON with JsonTextReader, writing JSON with JsonTextWriter</para>
</listItem>
</list>
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CreateJsonSchemaManually" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates a new <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference>
instance manually in code.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\CreateJsonSchemaManually.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JTokenIsValid" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample validates a <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
using the <codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema)</codeEntityReference>
extension method.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\JTokenIsValid.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JTokenIsValidWithMessages" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample validates a <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
using the <codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema)</codeEntityReference>
extension method and returns error messages.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\JTokenIsValidWithMessages.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JTokenValidateWithEvent" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample validates a <codeEntityReference>T:Newtonsoft.Json.Linq.JObject</codeEntityReference>
using the <codeEntityReference>M:Newtonsoft.Json.Schema.Extensions.IsValid(Newtonsoft.Json.Linq.JToken,Newtonsoft.Json.Schema.JsonSchema)</codeEntityReference>
extension method and raises an event for each validation error.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\JTokenValidateWithEvent.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonSchemaParse" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample parses a <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference>
from JSON</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\JsonSchemaParse.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="JsonValidatingReaderAndSerializer" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample validates JSON while deserializing an object using
<codeEntityReference>T:Newtonsoft.Json.JsonValidatingReader</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\JsonValidatingReaderAndSerializer.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\JsonValidatingReaderAndSerializer.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="LoadJsonSchemaFromFile" 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 a <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference>
from a file.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\LoadJsonSchemaFromFile.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="RefJsonSchemaResolver" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample uses a <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchemaResolver</codeEntityReference>
to resolve schema references from different JSON documents.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\RefJsonSchemaResolver.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="SaveJsonSchemaToFile" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample saves a <codeEntityReference>T:Newtonsoft.Json.Schema.JsonSchema</codeEntityReference>
to a file.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Schema\SaveJsonSchemaToFile.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CustomContractResolver" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates a custom <codeEntityReference>T:Newtonsoft.Json.Serialization.IContractResolver</codeEntityReference>
that only serializes a type's properties that begin with a specified character.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\CustomContractResolver.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\CustomContractResolver.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CustomJsonConverter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates a custom <codeEntityReference>T:Newtonsoft.Json.JsonConverter</codeEntityReference>
that overrides serialization to add a keys property.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\CustomJsonConverter.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\CustomJsonConverter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="CustomTraceWriter" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample creates a custom <codeEntityReference>T:Newtonsoft.Json.Serialization.ITraceWriter</codeEntityReference>
that writes to
<externalLink>
<linkText>NLog</linkText>
<linkUri>http://nlog-project.org/</linkUri>
<linkTarget>_blank</linkTarget>
</externalLink>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\CustomTraceWriter.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\CustomTraceWriter.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DataContractAndDataMember" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample shows how .NET Framework attributes such as
<codeEntityReference>T:System.Runtime.Serialization.DataContractAttribute</codeEntityReference>,
<codeEntityReference>T:System.Runtime.Serialization.DataMemberAttribute</codeEntityReference> and
<codeEntityReference>T:System.NonSerializedAttribute</codeEntityReference>
can be used with Json.NET instead of Json.NET's own attributes.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DataContractAndDataMember.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DataContractAndDataMember.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DefaultValueAttributeIgnore" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample uses the <codeEntityReference>T:System.ComponentModel.DefaultValueAttribute</codeEntityReference>
to override the default value for a property and exclude it from serialization using
<codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference>.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DefaultValueAttributeIgnore.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DefaultValueAttributeIgnore.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DefaultValueHandlingIgnore" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample uses the <codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference> setting to
not serialize properties with a default value.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DefaultValueHandlingIgnore.cs" region="Types" title="Types" />
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DefaultValueHandlingIgnore.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeAnonymousType" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample deserializes JSON into an anonymous type.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DeserializeAnonymousType.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<topic id="DeserializeCollection" revisionNumber="1">
<developerConceptualDocument xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5" xmlns:xlink="http://www.w3.org/1999/xlink">
<introduction>
<para>This sample deserializes JSON into a collection.</para>
</introduction>
<section>
<title>Sample</title>
<content>
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DeserializeCollection.cs" region="Usage" title="Usage" />
</content>
</section>
</developerConceptualDocument>
</topic>

Some files were not shown because too many files have changed in this diff Show More