I get a similar Json from a service that I do not control:
"SomeKey": { "Name": "Some name", "Type": "Some type" }, "SomeOtherKey": { "Name": "Some other name", "Type": "Some type" }
I am trying to deserialize this line in a .Net class using NewtonSoft Json.Net, which works very well since my classes now look like this:
public class MyRootClass { public Dictionary<String, MyChildClass> Devices { get; set; } } public class MyChildClass { [JsonProperty("Name")] public String Name { get; set; } [JsonProperty("Type")] public String Type { get; set; } }
However, I would prefer a flatter version of my class without a dictionary:
public class MyRootClass { [JsonProperty("InsertMiracleCodeHere")] public String Key { get; set; } [JsonProperty("Name")] public String Name { get; set; } [JsonProperty("Type")] public String Type { get; set; } }
However, I donβt have a clue on how to achieve this, because I donβt know how to access the keys in a custom converter in the following way:
http://blog.maskalik.com/asp-net/json-net-implement-custom-serialization
Just in case anyone cares, a link to a page where you can find actual Json string samples: Ninjablocks Restore API documentation with json samples
source share