-Documentation
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<topic id="ReadMultipleContentWithJsonReader" 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.JsonReader.SupportMultipleContent</codeEntityReference>
|
||||
to true so that multiple JSON fragments can be read from a <codeEntityReference>T:System.IO.Stream</codeEntityReference> or
|
||||
<codeEntityReference>T:System.IO.TextReader</codeEntityReference>.</para>
|
||||
</introduction>
|
||||
<section>
|
||||
<title>Sample</title>
|
||||
<content>
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Json\ReadMultipleContentWithJsonReader.cs" region="Types" title="Types" />
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Json\ReadMultipleContentWithJsonReader.cs" region="Usage" title="Usage" />
|
||||
</content>
|
||||
</section>
|
||||
</developerConceptualDocument>
|
||||
</topic>
|
||||
@@ -20,6 +20,7 @@
|
||||
<listItem><para><codeEntityReference>T:Newtonsoft.Json.JsonDictionaryAttribute</codeEntityReference> - Placed on dictionaries to control how they should be serialized as a JSON object.</para></listItem>
|
||||
<listItem><para><codeEntityReference>T:Newtonsoft.Json.JsonPropertyAttribute</codeEntityReference> - Placed on fields and properties to control how they should be serialized as a property in a JSON object.</para></listItem>
|
||||
<listItem><para><codeEntityReference>T:Newtonsoft.Json.JsonConverterAttribute</codeEntityReference> - Placed on either classes or fields and properties to specify which JsonConverter should be used during serialization.</para></listItem>
|
||||
<listItem><para><codeEntityReference>T:Newtonsoft.Json.JsonExtensionDataAttribute</codeEntityReference> - Placed on a collection field or property to deserialize properties with no matching class member into the specified collection and write values during serialization.</para></listItem>
|
||||
</list>
|
||||
|
||||
</introduction>
|
||||
@@ -101,10 +102,8 @@
|
||||
<section>
|
||||
<title>JsonIgnoreAttribute</title>
|
||||
<content>
|
||||
<!-- Uncomment this to create a sub-section outline
|
||||
<autoOutline /> -->
|
||||
<para>Excludes a field or property from serialization.</para>
|
||||
<para>The <codeEntityReference>T:System.NonSerializedAttribute</codeEntityReference> can be used as substitute for JsonIgnoreAttribute.</para>
|
||||
<para>The <codeEntityReference>T:System.NonSerializedAttribute</codeEntityReference> can be used as a substitute for JsonIgnoreAttribute.</para>
|
||||
</content>
|
||||
</section>
|
||||
|
||||
@@ -132,6 +131,17 @@
|
||||
and set the ItemConverterType property to the converter type you want to use.</para>
|
||||
</content>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>JsonExtensionDataAttribute</title>
|
||||
<content>
|
||||
<para>Instructs the <codeEntityReference>T:Newtonsoft.Json.JsonSerializer</codeEntityReference> to deserialize properties with no matching class member
|
||||
into the specified collection and write values during serialization.</para>
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DeserializeExtensionData.cs" region="Types" title="Types" />
|
||||
<code lang="cs" source="..\Src\Newtonsoft.Json.Tests\Documentation\Samples\Serializer\DeserializeExtensionData.cs" region="Usage" title="Usage" />
|
||||
</content>
|
||||
</section>
|
||||
|
||||
</sections>
|
||||
</section>
|
||||
<relatedTopics>
|
||||
|
||||
+5
-4
@@ -30,7 +30,7 @@
|
||||
<Topic id="JsonNetVsDotNetSerializers" visible="True" title="Json.NET vs .NET Serializers" />
|
||||
<Topic id="JsonNetVsWindowsDataJson" visible="True" title="Json.NET vs Windows.Data.Json" />
|
||||
<Topic id="Samples" visible="True" isExpanded="true" title="Samples">
|
||||
<Topic id="d6e185d5-c992-44fc-8d8f-d9acc2bbec2f" visible="True" noFile="true" isExpanded="true" title="Serializing JSON">
|
||||
<Topic id="d6e185d5-c992-44fc-8d8f-d9acc2bbec2f" visible="True" noFile="true" title="Serializing JSON">
|
||||
<Topic id="SerializeObject" visible="True" title="Serialize an Object" />
|
||||
<Topic id="SerializeCollection" visible="True" title="Serialize a Collection" />
|
||||
<Topic id="SerializeDictionary" visible="True" title="Serialize a Dictionary" />
|
||||
@@ -82,7 +82,7 @@
|
||||
<Topic id="SerializationCallbackAttributes" visible="True" title="Serialization Callback Attributes" />
|
||||
<Topic id="DataContractAndDataMember" visible="True" title="DataContract and DataMember Attributes" />
|
||||
<Topic id="DeserializeWithDependencyInjection" visible="True" title="Deserialize with dependency injection" />
|
||||
<Topic id="DefaultSettings" visible="True" isSelected="true" title="Serialize with DefaultSettings" />
|
||||
<Topic id="DefaultSettings" visible="True" title="Serialize with DefaultSettings" />
|
||||
<Topic id="SerializeImmutableCollections" visible="True" title="Serialize an immutable collection" />
|
||||
<Topic id="DeserializeImmutableCollections" visible="True" title="Deserialize an immutable collection" />
|
||||
<Topic id="SerializeExtensionData" visible="True" title="Serialize ExtensionData" />
|
||||
@@ -90,7 +90,7 @@
|
||||
<Topic id="DeserializeDateFormatString" visible="True" title="Deserialize DateFormatString" />
|
||||
<Topic id="SerializeDateFormatString" visible="True" title="Serialize DateFormatString" />
|
||||
</Topic>
|
||||
<Topic id="68b9fad2-5436-4e35-a734-9b9d751cc3e5" visible="True" noFile="true" isExpanded="true" title="LINQ to JSON">
|
||||
<Topic id="68b9fad2-5436-4e35-a734-9b9d751cc3e5" visible="True" noFile="true" title="LINQ to JSON">
|
||||
<Topic id="CreateJsonManually" visible="True" title="Create JSON manually" />
|
||||
<Topic id="CreateJsonCollectionInitializer" visible="True" title="Create JSON using Collection Initializers" />
|
||||
<Topic id="CreateJsonDeclaratively" visible="True" title="Create JSON declaratively with LINQ" />
|
||||
@@ -150,9 +150,10 @@
|
||||
<Topic id="DeserializeFromBson" visible="True" title="Deserialize from BSON" />
|
||||
<Topic id="DeserializeFromBsonCollection" visible="True" title="Deserialize a Collection from BSON" />
|
||||
</Topic>
|
||||
<Topic id="ca145ed0-f377-4f1c-9479-d1629082fc6e" visible="True" noFile="true" title="Reading and Writing JSON">
|
||||
<Topic id="ca145ed0-f377-4f1c-9479-d1629082fc6e" visible="True" noFile="true" isExpanded="true" title="Reading and Writing JSON">
|
||||
<Topic id="ReadJsonWithJsonTextReader" visible="True" title="Read JSON with JsonTextReader" />
|
||||
<Topic id="WriteJsonWithJsonTextWriter" visible="True" title="Write JSON with JsonTextWriter" />
|
||||
<Topic id="ReadMultipleContentWithJsonReader" visible="True" isSelected="true" title="Read Multiple Content With JsonReader" />
|
||||
<Topic id="CustomJsonReader" visible="True" title="Custom JsonReader" />
|
||||
<Topic id="CustomJsonWriter" visible="True" title="Custom JsonWriter" />
|
||||
</Topic>
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="icons\favicon.ico" />
|
||||
<None Include="Samples\Json\ReadMultipleContentWithJsonReader.aml" />
|
||||
<None Include="Samples\Serializer\SerializeImmutableCollections.aml" />
|
||||
<None Include="Samples\Serializer\SerializeExtensionData.aml" />
|
||||
<None Include="Samples\Serializer\SerializeDateFormatString.aml" />
|
||||
|
||||
@@ -57,4 +57,4 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("7.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18329")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18402")]
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
#if NETFX_CORE
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
|
||||
#elif ASPNETCORE50
|
||||
using Xunit;
|
||||
using Test = Xunit.FactAttribute;
|
||||
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
|
||||
#else
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Json
|
||||
{
|
||||
public class ReadMultipleContentWithJsonReader
|
||||
{
|
||||
#region Types
|
||||
public class Role
|
||||
{
|
||||
public string Name { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
string json = @"{ 'name': 'Admin' }{ 'name': 'Publisher' }";
|
||||
|
||||
IList<Role> roles = new List<Role>();
|
||||
|
||||
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||
reader.SupportMultipleContent = true;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!reader.Read())
|
||||
break;
|
||||
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
Role role = serializer.Deserialize<Role>(reader);
|
||||
|
||||
roles.Add(role);
|
||||
}
|
||||
|
||||
foreach (Role role in roles)
|
||||
{
|
||||
Console.WriteLine(role.Name);
|
||||
}
|
||||
|
||||
// Admin
|
||||
// Publisher
|
||||
#endregion
|
||||
|
||||
Assert.AreEqual(2, roles.Count);
|
||||
Assert.AreEqual("Admin", roles[0].Name);
|
||||
Assert.AreEqual("Publisher", roles[1].Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,7 @@
|
||||
<Compile Include="Documentation\Samples\Bson\DeserializeFromBsonCollection.cs" />
|
||||
<Compile Include="Documentation\Samples\Bson\SerializeToBson.cs" />
|
||||
<Compile Include="Documentation\Samples\Json\CustomJsonWriter.cs" />
|
||||
<Compile Include="Documentation\Samples\Json\ReadMultipleContentWithJsonReader.cs" />
|
||||
<Compile Include="Documentation\Samples\Json\ReadJsonWithJsonTextReader.cs" />
|
||||
<Compile Include="Documentation\Samples\Json\CustomJsonReader.cs" />
|
||||
<Compile Include="Documentation\Samples\Json\WriteJsonWithJsonTextWriter.cs" />
|
||||
|
||||
@@ -76,4 +76,4 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("7.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18329")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18402")]
|
||||
|
||||
@@ -92,5 +92,5 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("7.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18329")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18402")]
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
Reference in New Issue
Block a user