Can I deserialize json to anonymous type in c#?

前端 未结 7 695
半阙折子戏
半阙折子戏 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:27

    Finding the substring is a dangerous optimisation.

    Is it worth optimising the process (compared to a JSON deserialization) and safe to do such a lookup ? We can't answer yes because it's mostly dependent on the context. But I feel like saying NO because it's obviously looking for trouble: Even if it works now, it may get broken in the future when the structure or contents of you object changes.

提交回复
热议问题