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

posted on 2020-06-08 19:46  庭前花满留晚照  阅读(1031)  评论(0编辑  收藏  举报

导航