I'm currently trying to deserialize a Json-feed that I'm receiving from an external process. The problem is that the JSON is relying heavily on anonymous classes which I don't know how to properly deserialize.
I'm hoping anyone here could help me.
Below is a piece of the JSON:
[ 14, { "a": [ "5877.40000", 0, "0.89672653" ], "b": [ "5877.30000", 6, "6.20000000" ], "c": [ "5877.40000", "0.02216247" ] }, "name", "description" ] So my class currently looks like this, but this is not correct:
public class TestClass { public int ChannelID { get; set; } // 14 in the sample public TestSubClass test { get; set; } // THIS IS THE ANONYMOUS ONE public string ChannelName { get; set; } // "name" in the sample public string ChannelDescription { get; set; } // "description in the sample" } public class TestSubClass { public TestOption1Class a { get; set; } public TestOption1Class b { get; set; } public TestOption2Class c { get; set; } } public class TestOption1Class { public float price { get; set; } public int amount { get; set; } public float unitWeight { get; set; } } public class TestOption2Class { public float price { get; set; } public float unitWeight { get; set; } } Now these classes are wrong. I am assuming I need to use some sort of key/value pair or something, but I'm not sure on how to achieve that. If somebody know how I could deserialize this properly, that would be great.
In order to be complete, the code to deserialize is below:
var test = JsonConvert.DeserializeObject<List<TestClass>>(jsonTest);
TestSubClassis an anonymous, if you know its structure? Is it always a 3 tokens inside it? Does it make sense to declare it as an array?float).