-1

I have this working code that uses Newtonsoft to deserialize a json string into a dynamic object.

 dynamic json = JsonConvert.DeserializeObject<dynamic>(ResultJson);

and then I search for a particular token to get its property name

var countries = json.SelectTokens("$..CountryValue");
foreach (var token in countries)
{

}

Using Visual Studio watch window during debugging, I can see the token has {[ { "Code": "USA" }]}

My question is how do I grab the property value USA from token?

Updated: I managed to extract the property value with token[0].Code. Problem solved.

Steve
  • 2,963
  • 15
  • 61
  • 133
  • 1
    don't include the `` generic argument? Or, use JObject/JArray parsing: https://www.newtonsoft.com/json/help/html/QueryJsonDynamic.htm – gunr2171 Feb 24 '21 at 23:36
  • 1
    Does this answer your question? [Deserialize json object into dynamic object using Json.net](https://stackoverflow.com/questions/4535840/deserialize-json-object-into-dynamic-object-using-json-net) – gunr2171 Feb 24 '21 at 23:37
  • It's okay. I solved already with `token[0].Code` – Steve Feb 25 '21 at 00:42

1 Answers1

0

I managed to extract the property value with token[0].Code

Steve
  • 2,963
  • 15
  • 61
  • 133