【发布时间】:2021-09-30 22:07:41
【问题描述】:
我希望重用项目中的代码,该代码看起来像第一个代码块,但需要一些帮助执行 json 架构(第二个代码块),它包含两个对象和一个布尔值而不仅仅是一个对象?
猜测 som 之类的 allOf 但不太确定如何使用它。
string schemaJson = @"{
'description': 'onlyOneObject',
'type': 'object',
'properties': {
'personId': { 'type': 'string', 'minLength' : 6 },
'code': { 'type': 'string', 'minLength' : 3 }
},
'required' : [ 'personId' , 'code' ]
}";
JSchema schema = JSchema.Parse(schemaJson);
所以我需要你的专家帮助,因为我不太确定语法。
string schemaJson = @"{
'description': 'firstObject',
'type': 'object',
'properties': {
'personId': { 'type': 'string', 'minLength' : 6 },
'code': { 'type': 'string', 'minLength' : 3 }
},
'required' : [ 'personId' , 'code' ]
'description': 'secondObject', ??? Can I write the second object like this???
'type': 'object',
'properties': {
'name': { 'type': 'string', 'minLength' : 6 },
'code2': { 'type': 'string', 'minLength' : 3 }
},
'required' : [ 'name' , 'code2' ]
'description': 'yeahOrNay',
'type': 'bool'
something something for bool???
}";
【问题讨论】:
-
请尝试与我们分享Minimal, Reproducible Example
-
您能否与我们分享您要对其执行验证的示例 json?
-
不执行实际验证 >>
bool schemaValid = tmp.IsValid(schema, out errors)我想帮助你,我需要更多的上下文,但如果你不想提供,那就祝你有美好的一天.... -
@JoBo 请记住要友善。您可能需要重新阅读 StackOverflow 行为准则:stackoverflow.com/conduct
-
关于你的问题,你没有提供足够的信息让我提供答案。请分享您要验证的数据示例。 “我正在尝试创建一个不执行实际验证的 json 模式”在这种情况下,您需要解释为什么需要 JSON 模式。 JSON Schema 用于验证 JSON 数据。如果您不使用它进行验证,您可能还需要提供您正在使用的库,因为任何非验证都是特定于实现的。在你说我不知道 JSON Schema 之前,你不妨看看谁发布了最新版本。
标签: c# json json.net jsonschema jobjectformatter