3
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() 为 Newtonsoft.Json.Linq.JObject

那么如何将其反序列化为动态对象而不是 JObject

4

2 回答 2

4

目前还不清楚什么不适合您以及您为什么关心返回类型,但您可以直接访问反序列化对象的属性,如下所示:

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;
...
于 2013-04-19T15:30:13.173 回答
0

你可能想要类似的东西

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

这也可能适合您的需求(未经测试)

dynamic d = JsonConvert.DeserializeObject<ExpandoObject>(json);
于 2013-04-19T15:30:12.393 回答