mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-24 09:54:58 +00:00
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Crestron.SimplSharp;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace PepperDash.Essentials.Core
|
|
{
|
|
public static class JsonExtensions
|
|
{
|
|
public static List<JToken> FindTokens(this JToken containerToken, string name)
|
|
{
|
|
List<JToken> matches = new List<JToken>();
|
|
FindTokens(containerToken, name, matches);
|
|
return matches;
|
|
}
|
|
|
|
private static void FindTokens(JToken containerToken, string name, List<JToken> matches)
|
|
{
|
|
if (containerToken.Type == JTokenType.Object)
|
|
{
|
|
foreach (JProperty child in containerToken.Children<JProperty>())
|
|
{
|
|
if (child.Name == name)
|
|
{
|
|
matches.Add(child.Value);
|
|
}
|
|
FindTokens(child.Value, name, matches);
|
|
}
|
|
}
|
|
else if (containerToken.Type == JTokenType.Array)
|
|
{
|
|
foreach (JToken child in containerToken.Children())
|
|
{
|
|
FindTokens(child, name, matches);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |