[英]JsonSchema validation of string containing two objects and one bool?
我希望重用一個看起來像第一個代碼塊但需要一些幫助來執行 json 架構(第二個代碼塊)的代碼,該架構包含兩個對象和一個布爾值,而不僅僅是一個 object?
猜測 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???
}";
所以這就是我正在尋找的答案......包含兩個對象和一個 bool 的 schemaJson 結構。 (不是每一個道具都需要驗證,因為它是我所追求的結構)
感謝我自己,因為有些人認為根據給定的信息無法回答:)
string schemaJson = @"{
'description': 'myObject',
'type': 'object',
'properties': {
'firstObject': {
'type': 'object',
'properties': {
'NUMBER': { 'type': 'integer' }
}
},
'secondObject': {
'type': 'object',
'properties': {
'NUMBER': { 'type': 'integer' }
}
},
'yeahOrNay': { 'type': 'boolean' }
},
}";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.