一,学习JSON
1.JSON样式一:
2.JSON样式二(JSON 对象中可以包含另外一个 JSON 对象):
3.JavaScript获取JSON里对应值的方法
4.JavaScript遍历JSON值的方法
5.JSON.parse(): 将一个 JSON 字符串转换为 JavaScript 对象。
6.JSON.stringify(): 于将 JavaScript 值转换为 JSON 字符串。
二,学习Json Schema
格式分析:
$schema | 描述 |
$schema | $schema 关键字状态,表示这个模式与 v4 规范草案书写一致。 |
title | 标题,用来描述结构 |
description | 描述 |
type | 类型 |
properties | 定义属性 |
required | 必需属性 |
(1)object类型的关键字
type 类型
properties 定义属性
required 必需属性
maxProperties 最大属性个数
minProperties 最小属性个数
(2)array的属性
items array 每个元素的类型
minItems 约束属性,数组最小的元素个数
maxItems 约束属性,数组最大的元素个数
uniqueItems 约束属性,每个元素都不相同
additionalProperties 约束items的类型,不建议使用
Dependencies 属性依赖
(3)string的属性
maxLength 定义字符串的最大长度,>=0
minLength 定义字符串的最小长度,>=0
pattern 用正则表达式约束字符串
(4)integer的属性
minimum 最小值
exclusiveMinimum 如果存在 "exclusiveMinimum" 并且具有布尔值 true,如果它严格意义上大于 "minimum" 的值则实例有效。
maximum 约束属性,最大值
exclusiveMaximum 如果存在 "exclusiveMinimum" 并且具有布尔值 true,如果它严格意义上小于 "maximum" 的值则实例有效。
multipleOf 是某数的倍数,必须大于0的整数
(5)number的属性
minimum 最小值
exclusiveMinimum 如果存在 "exclusiveMinimum" 并且具有布尔值 true,如果它严格意义上大于 "minimum" 的值则实例有效。
maximum 约束属性,最大值
exclusiveMaximum 如果存在 "exclusiveMinimum" 并且具有布尔值 true,如果它严格意义上小于 "maximum" 的值则实例有效。
(6)boolean的属性
true or false
(7)enum,null
2.Json schema 应用关键字
(1)$ref 用来引用其它schema
2.1.Json schema 应用关键字-definitions
当一个schema写的很大的时候,可能需要创建内部结构体,再使用$ref进行引用,示列如下
三,C#读写JSON文件
0.JSON文件
1.读取(废弃,请使用序列化方法)
2.序列化与反序列化方法:
a.有实体:
b.无实体-反序列化
3.读取json文件的方法
a.第一版
b.第二版,改成泛型:
4.保存json文件的泛型方法
5.修改Value通过Key
作者:꧁执笔小白꧂