Skip to content

Instantly share code, notes, and snippets.

@darrenferguson
Created August 18, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenferguson/b18e62e9809846059be2 to your computer and use it in GitHub Desktop.
Save darrenferguson/b18e62e9809846059be2 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
string json =
@"[
{
""X"":
{
""Title"":""foo"",
""xxxx"":""xxxx""
},
""X"":
{
""twat"":""step"",
""ass"":""b""
}
},
{
""Y"":
{
""ZZ"":
{
""Title"":""bar"",
""xxxx"":""xxxx""
}
}
}
]";
JToken node = JToken.Parse(json);
WalkNode(node, n =>
{
foreach (var property in n.Properties().Where(x => x.Value.Type == JTokenType.String))
{
Console.Write(property.Name + " - > ");
Console.WriteLine(property.Value);
}
//if (token != null && token.Type == JTokenType.String)
//{
// string title = token.Value<string>();
// Console.WriteLine(title);
//}
});
}
static void WalkNode(JToken node, Action<JObject> action)
{
if (node.Type == JTokenType.Object)
{
action((JObject)node);
foreach (JProperty child in node.Children<JProperty>())
{
WalkNode(child.Value, action);
}
}
else if (node.Type == JTokenType.Array)
{
foreach (JToken child in node.Children())
{
WalkNode(child, action);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment