Created
October 25, 2011 09:21
-
-
Save JohannesEH/1311997 to your computer and use it in GitHub Desktop.
JSON to dynamic object function
This file contains 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
private static dynamic CreateDynamicFromObjectGraph(object input) | |
{ | |
if(input is IDictionary<string, object>) | |
{ | |
var result = (IDictionary<string, object>)(new ExpandoObject()); | |
foreach (var pair in (IDictionary<string, object>)input) | |
result.Add(pair.Key, CreateDynamicFromObjectGraph(pair.Value)); | |
return result; | |
} | |
return input; | |
} |
This file contains 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
var json = new JavaScriptSerializer(); | |
dynamic obj = CreateDynamicFromObjectGraph(json.DeserializeObject(someJson)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment