From IT Skills
Jump to: navigation, search

How deserialize JSON[edit]

in dotNet[edit]

  • simple Regex
  • from System.Runtime.Serialization.dll by JsonReaderWriterFactory or DataContractJsonSerializer (faster than JavaScriptSerializer)
  • from System.Web.Extensions.dll by JavaScriptSerializer
  • from System.Web.Helpers.dll by Json.Decode
  • Windows.Data.Json for Win 8+
  • Newtonsoft.Json.NET and Json.Linq or Path
  • System.Text.Json

inherited classes deserialization problem[edit]

DataContractJsonSerializer cannot deserialize complex objects, and __type is not managed.

XmlSerializer cannot help with complex objects too, only DataContractSerializer is needed.

marking properties[edit]

opt-in is turned on when class marked by DataContract

As of .NET 3.0, you can use DataContract instead of Serializable. With the DataContract though, you will need to either "opt-in" by marking the serializable fields with the DataMember attribute; or "opt-out" using the IgnoreDataMember... opt-out by default will only serialize public members, while opt-in will only serialize the marked members (regardless of protection level)

Wcf uses Typewriter

Newtonsoft.Json uses JsonProperty, JsonIgnore attributes.

in TypeScript[edit]