反序列化 type/naming-faulty JSON 时抛出异常?
Throwing exception on deserializing type/naming-faulty JSON?
是否可以让 JsonConvert.Deserialize<T>()
在传入的 JSON 与指定类型的属性不完全匹配时抛出异常 names/types?
它只是用默认值填充道具。
您可以在 https://www.newtonsoft.com/jsonschema
使用 Json.NET 架构
这是来自它的主页:
JSchema schema = JSchema.Parse(@"{
'type': 'object',
'properties': {
'name': {'type':'string'},
'roles': {'type': 'array'}
}
}");
JObject user = JObject.Parse(@"{
'name': 'Arnie Admin',
'roles': ['Developer', 'Administrator']
}");
bool valid = user.IsValid(schema);
// true
是否可以让 JsonConvert.Deserialize<T>()
在传入的 JSON 与指定类型的属性不完全匹配时抛出异常 names/types?
它只是用默认值填充道具。
您可以在 https://www.newtonsoft.com/jsonschema
使用 Json.NET 架构这是来自它的主页:
JSchema schema = JSchema.Parse(@"{
'type': 'object',
'properties': {
'name': {'type':'string'},
'roles': {'type': 'array'}
}
}");
JObject user = JObject.Parse(@"{
'name': 'Arnie Admin',
'roles': ['Developer', 'Administrator']
}");
bool valid = user.IsValid(schema);
// true