Can I deserialize json to anonymous type in c#?

前端 未结 7 711
半阙折子戏
半阙折子戏 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.

提交回复
热议问题