I want to retrieve a single value from a json string.
Previously I used Newtonsoft like this:
var jsonString = @"{ ""MyProp"" : 5 }";
dynamic obj = Newtonsoft.Json.Linq.JObject.Parse(jsonString);
Console.WriteLine(obj["MyProp"].ToString());
But I can't seem to get it to work in .NET 6:
I've tried this so far:
var jsonString = @"{ ""MyProp"" : 5 }";
dynamic obj = await System.Text.Json.JsonSerializer.Deserialize<dynamic>(jsonString);
Console.WriteLine(obj.MyProp.ToString());
which results in this error:
Unhandled exception. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The best overloaded method match for 'System.Text.Json.JsonElement.this[int]' has some invalid arguments