Can I deserialize json to anonymous type in c#?

前端 未结 7 693
半阙折子戏
半阙折子戏 2021-02-04 07:13

I read from the DB a long json. I want just one attribute of that json.

I have got two options: a. Create an interface for that json and deserialize to that interface.

相关标签:
7条回答
  • 2021-02-04 07:38

    You can do:

    var result = JsonConvert.DeserializeAnonymousType(json, new { Foo="", Bar=""});
    

    This will return a dynamic object with the fields you defined.

    0 讨论(0)
提交回复
热议问题