Created
July 24, 2019 17:44
-
-
Save c272/e7b280eed09faa80b7efb8e0c6eb552e to your computer and use it in GitHub Desktop.
Dynamic JSON parsing in .NET.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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