sino
sino

Reputation: 776

Newton.JSON convert dynamic object to JObject instead of dynamic object

string  result ="{"AppointmentID":463236,"Message":"Successfully Appointment Booked","Success":true,"MessageCode":200,"isError":false,"Exception":null,"ReturnedValue":null}"

   dynamic d = JsonConvert.DeserializeObject<dynamic>(result);

d.GetType () is Newtonsoft.Json.Linq.JObject

so how to deserialize it to dynamic object instead of JObject

Upvotes: 5

Views: 16095

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039140

It's not quite clear what is not working for you and why you care about the return type but you could directly access the properties of the deserialized object like this:

string result = @"{""AppointmentID"":463236,""Message"":""Successfully Appointment Booked"",""Success"":true,""MessageCode"":200,""isError"":false,""Exception"":null,""ReturnedValue"":null}";
dynamic d = JsonConvert.DeserializeObject<dynamic>(result);

string message = d.Message;
int code = d.MessageCode;
...

Upvotes: 4

Jakob Bowyer
Jakob Bowyer

Reputation: 34718

You probably want something like

var values = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(json);

This might also suit your needs (untested)

dynamic d = JsonConvert.DeserializeObject<ExpandoObject>(json);

Upvotes: 0

Related Questions