-Documentation
-Fixed JObject loading JSON with comments -Fixed error when using a Specified property with no setter -Fixed transient constructor error on Windows Phone 7 -Fixed deserializing null values into nullable generic dictionaries
This commit is contained in:
+35
-21
@@ -211,12 +211,12 @@
|
||||
<h4>
|
||||
<strong>Objects</strong></h4>
|
||||
<p>
|
||||
.NET types that don’t fall into any other category listed below (i.e. aren’t lists,
|
||||
.NET types that don't fall into any other category listed below (i.e. aren't lists,
|
||||
dictionaries, dynamic, implement ISerializable, etc) are serialized as JSON objects.</p>
|
||||
<p>
|
||||
By default types are serialized in opt-out mode. What that means is all public fields
|
||||
and properties with getters are automatically serialized to JSON and members that
|
||||
shouldn’t be serialized are opted-out using the JsonIgnoreAttribute. To serialize
|
||||
shouldn't be serialized are opted-out using the JsonIgnoreAttribute. To serialize
|
||||
private members the JsonPropertyAttribute can be placed on private fields and properties
|
||||
or the DefaultMembersSearchFlags can be changed on DefaultContractResolver to change
|
||||
how members are serialized on all types.</p>
|
||||
@@ -251,7 +251,7 @@
|
||||
<p>
|
||||
.NET dictionaries (types that inherit from IDictionary) are converted to JSON objects.
|
||||
Note that only the dictionary name/values will be written to the JSON object when
|
||||
serializing and properties on the JSON object will be added to the dictionary’s
|
||||
serializing and properties on the JSON object will be added to the dictionary's
|
||||
name/values when deserializing. Additional members on the .NET dictionary are ignored
|
||||
during serialization.</p>
|
||||
<p>
|
||||
@@ -263,40 +263,54 @@
|
||||
<h4>
|
||||
<strong>Untyped Objects</strong></h4>
|
||||
<p>
|
||||
.NET properties on a class that don’t specify a type (i.e. they are just object)
|
||||
.NET properties on a class that don't specify a type (i.e. they are just object)
|
||||
are serialized as usual. When untyped properties are deserialized the serializer
|
||||
has no way to know what type to create (unless type name handling is enabled and
|
||||
the JSON contains the type names).</p>
|
||||
<p>
|
||||
For these untyped properties the Json.NET serializer will read the JSON into LINQ
|
||||
to JSON objects and set them to the property.
|
||||
to JSON objects and set them to the property. JObject will be created for JSON objects,
|
||||
JArray will be created for JSON arrays and JValue for primitive JSON values.
|
||||
</p>
|
||||
<h4>
|
||||
<strong>Dynamic</strong></h4>
|
||||
<p>
|
||||
.NET dynamic objects (introduced in .NET 4) are serialized as JSON objects. A property
|
||||
is written for every member name returned by IDynamicMetaObjectProvider.GetDynamicMemberNames.</p>
|
||||
<p>
|
||||
When deserializing the serializer first attempts to set JSON property values on
|
||||
a normal .NET member with the matching name. If no .NET member is found with the
|
||||
property name then the serializer will call SetMember on the dynamic object.</p>
|
||||
<p>
|
||||
Because a dynamic property on a class doesn’t specify a type, Json.NET has no way
|
||||
to know what type to create for it when deserializing (unless type name handling
|
||||
is enabled and the JSON contains the type name). LINQ to JSON objects will be created
|
||||
for the JSON.
|
||||
There are two different usages of dynamic (introduced in .NET 4) in .NET. The first
|
||||
are .NET properties with a type of dynamic. Dynamic proeprties behave like properties
|
||||
declared as object, any value can be assigned to it, but the difference being that
|
||||
properties and methods can be called on a dynamic property without casting. In Json.NET
|
||||
dynamic properties are serialized and deserialized exactly the same as untyped objects:
|
||||
because dynamic isn't an actual type Json.NET falls back to deserializing the JSON
|
||||
as LINQ to JSON objects.
|
||||
</p>
|
||||
<p>
|
||||
The second usage of dynamic in .NET are classes that implement <a href="http://msdn.microsoft.com/en-us/library/system.dynamic.idynamicmetaobjectprovider.aspx"
|
||||
target="_blank">IDynamicMetaObjectProvider</a>. This interface lets the implementor
|
||||
create dynamic objects that intercept the property and method calls on an object
|
||||
and use them. <a href="http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject.aspx"
|
||||
target="_blank">ExpandoObject</a> is a good example of a dynamic object.
|
||||
</p>
|
||||
<p>
|
||||
Dynamic objects are serialized as JSON objects. A property is written for every
|
||||
member name returned by <a href="http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicmetaobject.getdynamicmembernames.aspx"
|
||||
target="_blank">DynamicMetaObject.GetDynamicMemberNames</a>.</p>
|
||||
<p>
|
||||
When deserializing dynamic objects the serializer first attempts to set JSON property
|
||||
values on a normal .NET member with the matching name. If no .NET member is found
|
||||
with the property name then the serializer will call SetMember on the dynamic object.
|
||||
Because there is no type information for dynamic members on a dynamic object the
|
||||
values assigned to them will be LINQ to JSON objects</p>
|
||||
<h4>
|
||||
<strong>ISerializable</strong></h4>
|
||||
<p>
|
||||
Types that implement ISerializable are serialized as JSON objects. When serializing
|
||||
only the values returned from ISerializable.GetObjectData are used; members on the
|
||||
type are ignored. When deserializing the constructor with a SerializationInfo and
|
||||
StreamingContext is called, passing the JSON object’s values.</p>
|
||||
StreamingContext is called, passing the JSON object's values.</p>
|
||||
<p>
|
||||
In situations where this behaviour is not wanted the JsonObjectAttribute can be
|
||||
placed on a .NET type that implements ISerializable to force it to be serialized
|
||||
as a normal JSON object.
|
||||
In situations where this behavior is not wanted the JsonObjectAttribute can be placed
|
||||
on a .NET type that implements ISerializable to force it to be serialized as a normal
|
||||
JSON object.
|
||||
</p>
|
||||
<h4>
|
||||
<strong>LINQ to JSON</strong></h4>
|
||||
@@ -313,7 +327,7 @@
|
||||
all other tests.</p>
|
||||
<p>
|
||||
JsonConverters can be defined and specified in a number of places: in an attribute
|
||||
on a member, in an attribute on a class and added to the JsonSerializer’s converters
|
||||
on a member, in an attribute on a class and added to the JsonSerializer's converters
|
||||
collection. The priority of which JsonConverter is used is the JsonConverter defined
|
||||
by attribute on a member then the JsonConverter defined by an attribute on a class
|
||||
and finally any converters passed to the JsonSerializer.</p>
|
||||
|
||||
Reference in New Issue
Block a user