zoukankan      html  css  js  c++  java
  • JsonSchema 解析示例

     1     /// <summary>
     2     /// JsonSchema Parse Demo
     3     /// </summary>
     4     public class JsonSchema
     5     {
     6         private int RecursionCnt = 0;
     7         private int RecursionCntMax = 100;
     8 
     9         public void Parse(dynamic schema)
    10         {
    11             RecursionCnt = RecursionCnt + 1;
    12 
    13             if (RecursionCnt > RecursionCntMax)
    14             {
    15                 return;
    16             }
    17 
    18             if (schema.items != null)
    19             {
    20                 Parse(schema.items);
    21             }
    22 
    23             if (schema.properties != null)
    24             {
    25                 foreach (var property in schema.properties)
    26                 {
    27                     if (property.Value.objectname == null)
    28                     {
    29                         foreach (var item in property)
    30                         {
    31                             Parse(item);
    32                         }
    33                     }
    34                     else
    35                     {
    36                         //获取需要的键值对(Key对name的value)
    37                         string name = property.Value.name;
    38                     }
    39                 }
    40             }
    41         }
    42     }

           

            JsonSchema 参见:http://json-schema.org/
            Json.NET Schema 参见:https://www.newtonsoft.com/jsonschema

  • 相关阅读:
    类和迭代器
    使用委托调用函数
    自定义类和集合
    带函数的参数返回函数的最大值
    使用程序调试输出窗口
    自定义类
    类和结构
    全局参数
    带参数的函数返回数组之和
    IS运算符
  • 原文地址:https://www.cnblogs.com/xuejietong/p/13067909.html
Copyright © 2011-2022 走看看