At a high level, the Json.NET serializer can convert primitive .NET values into primitive JSON values, can convert .NET arrays and collections to JSON arrays, and can convert everything else to JSON objects.Json.NET can throw a slip if it encounters incorrect JSON once deserializing a worth. for instance, if the serializer encounters a JSON property with AN array of values and also the variety of matching .NET property isn’t a set, then a slip are thrown, and vice-versa.
Breakdown of Type Serialization
.NET sorts that do not make up the other class listed below (i.e. are not lists, dictionaries, dynamic, implement ISerializable, etc.) ar serialized as JSON objects. You’ll be able to additionally force a kind to be serialized as a JSON object by inserting the JsonObjectAttribute on the sort. By default a type’s properties ar serialized in opt-out mode. What meaning is that each one public fields and properties with getters ar mechanically serialized to JSON, and fields and properties that should not be serialized ar opted-out by inserting JsonIgnoreAttribute on them. To serialise personal members, the JsonPropertyAttribute is placed on personal fields and properties. Types also can be serialized victimisation opt-in mode. solely properties and fields that have a JsonPropertyAttribute or DataMemberAttribute on them are going to be serialized. Opt-in mode for Associate in nursing object is such as by inserting the JsonObjectAttribute or DataContractAttribute on the sort.Finally, sorts is serialized employing a field’s mode. All fields, each public and personal, ar serialized and properties ar neglected. this could be such as by setting MemberSerialization.Fields on a kind with the JsonObjectAttribute or by victimisation the .NET SerializableAttribute and setting IgnoreSerializableAttribute on DefaultContractResolver to false.
IEnumerable, Lists, and Arrays
.NET lists (types that inherit from IEnumerable) and .NET arrays square measure regenerate to JSON arrays. as a result of JSON arrays solely support a variety of values and not properties, any extra properties and fields declared on .NET collections aren’t serialized. In things wherever a sort implements IEnumerable however a JSON array isn’t wished, then the JsonObjectAttribute is placed on the kind to force it to be serialized as a JSON object instead.JsonArrayAttribute has choices on that to customise the JsonConverter, sort name handling, and reference handling that square measure applied to assortment things.Note that if TypeNameHandling or PreserveReferencesHandling has been enabled for JSON arrays on the serializer, then JSON arrays square measure wrapped during a containing object. the item can have the kind name/reference properties and a $values property, which can have the gathering knowledge.When deserializing, if a member is typewritten because the interface IListT, then it’ll be deserialized as a List.
Dictionaries and Hash tables
.NET dictionaries (types that inherit from IDictionary) ar regenerate to JSON objects. Note that solely the wordbook name/values are written to the JSON object once serializing, and properties on the JSON object are supplementary to the dictionary’s name/values once deserializing. further members on the .NET wordbook ar unnoticed throughout serialisation.When serializing a wordbook, the keys of the wordbook ar regenerate to strings and used because the JSON object property names. The string written for a key are often bespoken by either preponderating ToString() for the key sort or by implementing a TypeConverter. A TypeConverter also will support changing a custom string back once more once deserializing a wordbook.JsonDictionaryAttribute has choices thereon to customise the JsonConverter, sort name handling, and reference handling that ar applied to assortment things.When deserializing, if a member is written because the interface IDictionary,TKey, TValue; then it’ll be deserialized as a Dictionary.
For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.
Helpline: 9814666333, 8699444666
Please fill the form and we shall contact you soon.