You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Json.NET supports error handling during serialization and deserialization. Error handling lets
19
+
you catch an error and choose whether to handle it and continue with serialization or let the error
20
+
bubble up and be thrown in your application.</p>
21
+
<p>Error handling is defined through two methods:
22
+
the Error event on JsonSerializer and the OnErrorAttribute.</p>
23
+
<h3>Error Event</h3>
24
+
25
+
<p>
26
+
The <ahref="./html/E_Newtonsoft_Json_JsonSerializer_Error.htm">Error</a> event is an event handler found on <ahref="./html/T_Newtonsoft_Json_JsonSerializer.htm">JsonSerializer</a>. The error event is raised whenever an
27
+
exception is thrown while serializing or deserialing JSON. Like all settings found on JsonSerializer
28
+
it can also be set on <ahref="./html/T_Newtonsoft_Json_JsonSerializer.htm">JsonSerializerSettings</a> and passed to the serialization methods on JsonConvert.</p>
<prestyle="margin: 0px;"><spanstyle="color: green;">// The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.</span></pre>
<p>If you aren't immediately handling an error and only want to perform an action against it once then
95
+
you can check to see whether the <ahref="./html/T_Newtonsoft_Json_Serialization_ErrorEventArgs.htm">ErrorEventArg</a>'s CurrentObject is equal to the OriginalObject.
96
+
OriginalObject is the object that threw the error and CurrentObject is the object that the event is being raised
97
+
against. They will only equal the first time the event is raised against the OriginalObject.</p>
98
+
99
+
<h3>OnErrorAttribute</h3>
100
+
101
+
<p>
102
+
The <ahref="./html/T_Newtonsoft_Json_Serialization_OnErrorAttribute.htm">OnErrorAttribute</a> works much like the other <ahref="SerializationCallbacks.html">.NET serialization attributes</a> that Json.NET supports.
103
+
To use it you simply place the attribute on a method which takes the correct parameters: a StreamingContext and a ErrorContext.
Copy file name to clipboardExpand all lines: Src/Doc/SerializingJSON.html
+4-3Lines changed: 4 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -92,12 +92,13 @@ <h5>DefaultValueHandling</h5>
92
92
the member's DefaultValueAttribute. Include or ignore.</p>
93
93
<h5>ObjectCreationHandling</h5>
94
94
<p>Controls how objects are created during deserialization. Auto, reuse, replace.</p>
95
+
<h5>TypeNameHandling</h5>
96
+
<p>Controls whether .NET type names are included in serialized JSON and read during deserialization when creating objects. None, Objects, Arrays or All.</p>
97
+
<h5>ConstructorHandling</h5>
98
+
<p>Controls how constructors are used when initializing objects during deserialization. Default or AllowNonPublicDefaultConstructor.</p>
95
99
<h5>Converters</h5>
96
100
<p>A collection of JsonConverters that will be used during serialization and
97
101
deserialization.</p>
98
-
<h5>TypeNameHandling</h5>
99
-
<p>Controls how .NET type names are used when serializing and deserializing JSON. If
Copy file name to clipboardExpand all lines: Src/Doc/doc.shfb
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@
7
7
<namespaceSummaryItem name="Newtonsoft.Json" isDocumented="True">The <b>Newtonsoft.Json</b> namespace provides classes that are used to implement the core services of the framework.</namespaceSummaryItem>
8
8
<namespaceSummaryItem name="Newtonsoft.Json.Converters" isDocumented="True">The <b>Newtonsoft.Json.Converters</b> namespace provides classes that inherit from <a href="T_Newtonsoft_Json_JsonConverter.htm">JsonConverter</a>.</namespaceSummaryItem>
9
9
<namespaceSummaryItem name="Newtonsoft.Json.Linq" isDocumented="True">The <b>Newtonsoft.Json.Linq</b> namespace provides classes that are used to implement LINQ to JSON.</namespaceSummaryItem>
10
+
<namespaceSummaryItem name="Newtonsoft.Json.Linq.ComponentModel" isDocumented="True">The <b>Newtonsoft.Json.Linq.ComponentModel</b> namespace provides classes for LINQ to JSON databinding.</namespaceSummaryItem>
10
11
<namespaceSummaryItem name="Newtonsoft.Json.Schema" isDocumented="True">The <b>Newtonsoft.Json.Schema</b> namespace provides classes that are used to implement JSON schema.</namespaceSummaryItem>
11
12
<namespaceSummaryItem name="Newtonsoft.Json.Serialization" isDocumented="True">The <b>Newtonsoft.Json.Linq</b> namespace provides classes that are used when serializing and deserializing JSON.</namespaceSummaryItem>
0 commit comments