Skip to content

Instantly share code, notes, and snippets.

@c272
Created July 24, 2019 17:44
Show Gist options
  • Select an option

  • Save c272/e7b280eed09faa80b7efb8e0c6eb552e to your computer and use it in GitHub Desktop.

Select an option

Save c272/e7b280eed09faa80b7efb8e0c6eb552e to your computer and use it in GitHub Desktop.
Dynamic JSON parsing in .NET.
string JSON = "{someObj:{someNested:\"\"}}";
dynamic arr = JObject.Parse(JSON); //JArray.Parse() for arrays
foreach (dynamic token in arr)
{
JTokenType type = ((JToken)token.value).Type;
switch (type)
{
case JTokenType.String:
Console.WriteLine(token.value);
break;
case JTokenType.Object:
Console.WriteLine(token.value.results.Last.value);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment