NewtonSoft.Json Serialize and Deserialize class with property of type IEnumerable

You don’t need to use JsonConverterAttribute, just keep your model clean and use CustomCreationConverter instead, the code is simpler: public class SampleConverter : CustomCreationConverter<ISample> { public override ISample Create(Type objectType) { return new Sample(); } } Then: var sz = JsonConvert.SerializeObject( sampleGroupInstance ); JsonConvert.DeserializeObject<SampleGroup>( sz, new SampleConverter()); Documentation: Deserialize with CustomCreationConverter

multiple JsonProperty Name assigned to single property

A simple solution which does not require a converter: just add a second, private property to your class, mark it with [JsonProperty(“name2”)], and have it set the first property: public class Specifications { [JsonProperty(“name1”)] public string CodeModel { get; set; } [JsonProperty(“name2”)] private string CodeModel2 { set { CodeModel = value; } } } Fiddle: … Read more

What’s the difference between DataContractJsonSerializer and JavaScriptSerializer?

The DataContractJsonSerializer is intended for use with WCF client applications where the serialized types are typically POCO classes with the DataContract attribute applied to them. No DataContract, no serialization. The mapping mechanism of WCF makes the sending and receiving very simple, but only if your platform is homogeneous. If you start mixing in different toolsets, … Read more

Newtonsoft JSON Deserialize

You can implement a class that holds the fields you have in your JSON class MyData { public string t; public bool a; public object[] data; public string[][] type; } and then use the generic version of DeserializeObject: MyData tmp = JsonConvert.DeserializeObject<MyData>(json); foreach (string typeStr in tmp.type[0]) { // Do something with typeStr } Documentation: … Read more

Polymorphism with gson

This is a bit late but I had to do exactly the same thing today. So, based on my research and when using gson-2.0 you really don’t want to use the registerTypeHierarchyAdapter method, but rather the more mundane registerTypeAdapter. And you certainly don’t need to do instanceofs or write adapters for the derived classes: just … Read more

JSON to TypeScript class instance? [duplicate]

This question is quite broad, so I’m going to give a couple of solutions. Solution 1: Helper Method Here’s an example of using a Helper Method that you could change to fit your needs: class SerializationHelper { static toInstance<T>(obj: T, json: string) : T { var jsonObj = JSON.parse(json); if (typeof obj[“fromJSON”] === “function”) { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)