Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deserialize Json to C# bool

Tags:

json

c#

I need help with a very simple question. How can I deserialize the json below to a C# bool without creating a wrapping root object. Thanks.

f
{"valid":false}
0
like image 798
gee Avatar asked Oct 20 '25 15:10

gee


1 Answers

If you are using Json.Net:

string json = @"{""valid"":true}";

var jo = JObject.Parse(json);
bool flag = jo.SelectToken("valid").Value<bool>();
like image 53
Alberto Avatar answered Oct 23 '25 03:10

Alberto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!