Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newtonsoft.Json.Linq.JObject 'does not contain a definition for X prop

Tags:

c#

I am trying to store the one property of my object in a variable and it gives me an error referring to my object does not have a definition for my property.

Error: 'Newtonsoft.Json.Linq.JObject' does not contain a definition for 'str'.

image with compiler error

This only happens within my project, if I do it within a separate compiler, everything runs correctly and it should be, but I don't understand why I get this error in the project.

https://dotnetfiddle.net/Jf5xQf

like image 833
Arnell Vasquez Corona Avatar asked Nov 01 '25 16:11

Arnell Vasquez Corona


1 Answers

The result you are receiving for JObject.Parse is of type JObject. To fetch the str value, you need to use

valorcito = d["str"]; 

You would be interested to read on querying Json with Linq with your current approach.

like image 93
Anu Viswan Avatar answered Nov 03 '25 04:11

Anu Viswan