• 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;
            }
    
            
        }
  • 相关阅读:
    Java 函数式编程—@FunctionalInterface----functional interface
    人月神话的博客
    如何度量复杂度
    泛型沉思录:创建模版与使用模版生成代码
    ioc与bean管理
    模式(思维)匹配是什么
    简析散光的成因,以及什么是散光的度数和轴位?
    概括是什么?
    思维与模型、世界观
    抽象、维度、层次与分析、综合
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/10074843.html
Copyright © 2020-2023  润新知