C# parser JSON get Key and value

/***********************************************************************
 *               C# parser JSON get Key and value
 * 说明:
 *     将配置放置在JSON文件中,通过Json.NET来解析JSON数据,由于配置是随时
 * 可能被改变,而且key也不是固定的,所以需要动态获取key、value来判断要怎么
 * 进行处理,不过在解析的时候发现JToken不能直接获取到Key、Value,通过JObject
 * 来进行获取。
 * 
 *                              2017-8-7 深圳 龙华樟坑村 曾剑锋
 **********************************************************************/


一、参考文档:
    一、NuGet Package Manager UI
        https://docs.microsoft.com/zh-cn/nuget/tools/package-manager-ui
    二、Introduction
        http://www.newtonsoft.com/json/help/html/Introduction.htm
    三、Read JSON from a file
        http://www.newtonsoft.com/json/help/html/ReadJson.htm
    四、Getting the name / key of a JToken with JSON.net
        https://stackoverflow.com/questions/21002297/getting-the-name-key-of-a-jtoken-with-json-net?answertab=votes
    五、C# Newtonsoft.Json之LINQ To Json实例(一)
        http://blog.csdn.net/u011127019/article/details/52486867
    六、使用JSON.net获取JToken的名称/键
        https://gxnotes.com/article/90134.html

二、Demo Code:
    using Newtonsoft.Json.Linq;
    
    ...

    JObject systemConfig = JObject.Parse(File.ReadAllText("config/system_config.json"));

    foreach (JToken item in systemConfig["display"]["resolution"])
    {
        Console.WriteLine(item.ToString());

        // 重新合成JObject对象来提取Key、Value
        JObject obj = JObject.Parse("{" + item.ToString() + "}");
        foreach(var pair in obj)
        {
            Console.WriteLine(pair.Key + "," + pair.Value);
        }
    }
原文地址:https://www.cnblogs.com/zengjfgit/p/7299890.html