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.
(Is it an overkill as I need just one attribute ?)
b. Find the substring I need (regex? )
which one is preferred ?
update: I’m using .net 3.5
Why don’t you deserialize using JSON.NET‘s “LINQ to JSON” approach (
JObjectetc) and just ask for the value you need by name?That’s sufficiently dynamic so you don’t need to create an interface for everything, but it’s a lot less brittle than using a regex.
(I believe JSON.NET also support’s
dynamicin .NET 4, but there’s no particular need to use it here.)