zoukankan      html  css  js  c++  java
  • JSON AST 生成MD

    使用 JsonLite 获取 JSON  AST

    class Program
        {
            static void Main(string[] args)
            {
    
                string fileName = $"{AppDomain.CurrentDomain.BaseDirectory}\json.txt";
    
                //SyntaxTree
    
                using (var stream = File.OpenRead(fileName))
                {
    
                    JsonObject temp =  Json.CreateAst(stream) as JsonObject;
    
                   string md =  Process(temp);
                }
                
                Console.WriteLine("Hello World!");
            }
    
            static string Process(JsonObject jsonObject)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("#### 返回参数");
                builder.AppendLine("| 字段  | 类型  | 字段名  | 说明 |");
                builder.AppendLine("| ------------ | ------------ | ------------ | ------------ | ------------ | ");
    
                //builder.AppendLine(ProcessFix(jsonObject));
    
                ProcessContent(jsonObject, 0, builder);
    
    
                return builder.ToString();
            }
    
            static string ProcessContent(JsonObject jsonObject, int deep, StringBuilder builder)
            {
                string format = string.Empty;
    
    
                if (deep == 0)
                    format = "|{0}|{1}|     ||";
                else
                {
                    int paddinLeft = 20 + (deep-1) * 20;
                    format = "|<span style="padding-left: "+paddinLeft.ToString()+"px">├─ {0}|{1}|     |    |     |";
                }
                
    
                foreach (var item in jsonObject.Members)
                {
                    if (item.Value.GetType() == typeof(JsonNumber))
                        builder.AppendFormat(format, item.Name, "number");
    
                    else if (item.Value.GetType() == typeof(JsonObject))
                    {
                        builder.AppendFormat(format, item.Name, "Object");
                        builder.Append(System.Environment.NewLine);
                        ProcessContent(item.Value as JsonObject, deep + 1, builder);
                    }
                    else if (item.Value.GetType() == typeof(JsonNull))
                        builder.AppendFormat(format, item.Name, "");
    
                    else if (item.Value.GetType() == typeof(JsonBoolean))
                        builder.AppendFormat(format, item.Name, "bool");
    
                    else if (item.Value.GetType() == typeof(JsonString))
                        builder.AppendFormat(format, item.Name, "string");
    
                    else
                        builder.AppendFormat(format, item.Name, "");
    
                    builder.Append(System.Environment.NewLine);
                }
    
    
                return string.Empty;
            }
    
            
        }
  • 相关阅读:
    P4630-[APIO2018]Duathlon铁人两项【圆方树】
    P4980-[模板]Pólya定理
    bzoj4589-Hard Nim【FWT】
    CF700E-Cool Slogans【SAM,线段树合并,dp】
    sqrt数据结构
    NOIP历年好题
    ACM题解吖
    [ZJOI2010]排列计数
    [CQOI2014]数三角形
    [SHOI2007]书柜的尺寸
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/10074843.html
Copyright © 2011-2022 走看看