Deserialize json object into dynamic object using Json.net

后端 未结 8 1721
感情败类
感情败类 2020-11-21 22:07

Is it possible to return a dynamic object from a json deserialization using json.net? I would like to do something like this:

dynamic jsonResponse = JsonConv         


        
8条回答
  •  迷失自我
    2020-11-21 22:53

    Yes it is possible. I have been doing that all the while.

    dynamic Obj = JsonConvert.DeserializeObject();
    

    It is a bit trickier for non native type. Suppose inside your Obj, there is a ClassA, and ClassB objects. They are all converted to JObject. What you need to do is:

    ClassA ObjA = Obj.ObjA.ToObject();
    ClassB ObjB = Obj.ObjB.ToObject();
    

提交回复
热议问题