Reputation: 181
Recently upgraded to Visual Studio 2017 and am facing a weird issue. I am not able to cast Netwonsoft.Json.Linq.JValue to a bool.
For instance, here is my object "actualObj" which contains a bool (shown in QuickWatch):
Now, when I cast it to a bool, which should have worked as per the docs, I get an invalid cast exception:
What should I be doing differently?
Upvotes: 7
Views: 3522
Reputation: 169340
Try to cast the Value
property of the JValue
:
JValue jv = actualObject as JValue;
if(jv != null)
{
bool b = (bool)jv.Value;
}
Upvotes: 10