Я думаю, что вы можете использовать словарь вместо анонимного объекта, посмотрите этот ответ
Обновление:
public class InsensitiveWrapper
{
private readonly JObject _rWrapped;
private readonly string _rLeafValue;
public InsensitiveWrapper(JObject jsonObj)
{
_rWrapped = jsonObj ?? throw new ArgumentNullException(nameof(jsonObj));
}
private InsensitiveWrapper(string value)
{
_rLeafValue = value ?? throw new ArgumentNullException(nameof(value));
}
public string Value => _rLeafValue ?? throw new InvalidOperationException("Value can be retrieved only from leaf.");
public InsensitiveWrapper this[string key]
{
get
{
object nonTyped = _rWrapped.GetValue(key, StringComparison.OrdinalIgnoreCase);
if (nonTyped == null)
throw new KeyNotFoundException($"Key {key} is not found.");
JObject jObject = nonTyped as JObject;
if (jObject == null)
return new InsensitiveWrapper(nonTyped.ToString());
return new InsensitiveWrapper(jObject);
}
}
}
public static async Task Main()
{
var input = new WebClient().DownloadString(@"http://ddragon.leagueoflegends.com/cdn/10.9.1/data/en_US/champion.json");
JObject json = (JObject)JsonConvert.DeserializeObject(input);
var dictionary = new InsensitiveWrapper(json);
var val = dictionary["data"]["Aatrox"]["key"].Value;
Console.WriteLine(val);
}