CSharp · Console
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
string req = @"
{
'creationRequestId':'A',
'value':
{
'amount':1.0,
'currencyCode':'USD'
}
}";
var token = JToken.Parse(req);
PrintLeafNames(token);
}
public static void PrintLeafNames(IEnumerable<JToken> tokens)
{
foreach (var token in tokens)
{
if (token.Type == JTokenType.Property)
{
JProperty prop = (JProperty)token;
if (!prop.Value.HasValues)
Console.WriteLine(prop.Name);
}
if (token.HasValues)
PrintLeafNames(token.Children());
}
}
}