Reputation: 17
My JSON string will be like
when I deserialize it using Newtonsoft.Json, instead of object I am getting below response
But it should be like below image
tried JsonConvert.DeserializeObject and JObject.Parse. is there any way to get in direct object structure when we deserialize it without knowing type?
Upvotes: -1
Views: 2914
Reputation: 10753
Try a dynamic? e.g.
dynamic thing = JObject.Parse("{Id:123, PhoneNumber: { Primary: 12345, Secondary: 78945}");
Console.WriteLine(thing.Id);
Console.WriteLine(thing.PhoneNumber);
Console.WriteLine(thing.PhoneNumber.Primary);
Upvotes: 2