I have stripped my query down as much as possible so as to focus on the question which I am hoping someone can answer.
All I'm wanting to do is deserialize json within a .net5 c# console application so that I can access the data like obj.user
I tried different methods but all appeared to require obj["user"], I then used newtonsoft (below) which gave me what I was after.
JSON
{
"ref": "2ef26371-972f-416e-8954-4cc0e7617115",
"user": "Jonny"
}
var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(bodyString);
Console.WriteLine(obj.user);
So I have a working solution but this took forever (a previous attempt could of worked) due to constantly getting the error [error CS1061: 'object' does not contain a definition for 'user' and no accessible extension method 'user' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)] within the immediate window when ever I typed obj.user (code stopped on the console.writeline line). I still get the error if I type obj.user but from within the running code Console.WriteLine(obj.user) works.
Can anyone please explain this to me?