我有使用架構檔案驗證 .json 檔案的代碼。我正在嘗試驗證值串列。但是如果檔案有一個“NO_DATA”、“EMPTY”或“NULL”作為值存盤,我想
Splunk_Status = Data_JSON.IsValid(Schema)是假的。
到目前為止我擁有的架構檔案:
"MN": {
"Type": "string",
"pattern": "[A-Z0-9]{14}",
},
失敗的檔案:
{
"MN": "NO_DATA",
}
要傳遞的檔案(它不必具有確切的模式,只需不為空即可):
{
"MN": "FS40-SR20D4-2C00W",
}
VB.net代碼:
schemaConn = ConfigurationManager.ConnectionStrings("LOCAL_SPLUNK_SCHEMA_PATH")
schema_path = schemaConn.ToString
Schema_String = My.Computer.FileSystem.ReadAllText(schema_path)
extra_str = backup_path
Schema = JsonSchema.Parse(Schema_String)
step_str = "Validate JSON File Data Using Schema"
Data_String = My.Computer.FileSystem.ReadAllText(Splunk_Info.FullName)
Data_JSON = JObject.Parse(Data_String)
Splunk_Status = Data_JSON.IsValid(Schema)
System.Threading.Thread.Sleep(1000)
Console.WriteLine("SPLUNK VALIDATE: " Splunk_Status.ToString)
If Splunk_Status = True Then
File_Validation = True
Console.WriteLine("File Location = " Splunk_Info.FullName)
GoTo Jump_ValidateHeader
Else
File_Validation = False
GoTo Jump_ValidateHeader
End If
uj5u.com熱心網友回復:
您可以通過組合not和enum關鍵字來禁止某些值:
"not": {
"enum": [ "NO_DATA", "EMPTY", "NULL" ]
}
您可以在此處閱讀有關這些關鍵字的資訊:
- https://json-schema.org/understanding-json-schema/reference/generic.html#id4
- https://json-schema.org/understanding-json-schema/reference/combining.html#id8
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/335620.html
標籤:json 网络 json.net jsonschema
