Reputation: 776
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
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
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