所以我有這個 json 模式:-
{
"type": "object",
"properties": {
"campaignType": {
"type": "string",
"enum": [
"export"
]
},
"clientid": {
"type": "integer",
"minimum": 1
},
"select": {
"type": "object",
"minProperties": 1,
"anyOf": [
{
"required": [
"list"
]
},
{
"required": [
"segment"
]
}
],
"properties": {
"list": {
"type": "array",
"items": {
"type": "integer"
}
},
"segment": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"attributes": {
"type": "array",
"minItems": 2,
"items": {
"type": "string",
"contains": ["fk", "uid"]
}
}
},
"required": [
"campaignType",
"clientid",
"select",
"attributes"
]
}
在這里,我想讓屬性欄位的值“fk”、“uid”固定,并且必須允許其他欄位值帶有“fk”和“uid”。使用以下代碼,我在傳遞附加值時遇到錯誤:- { "campaignType":"export", "clientid":107311, "select":{ "segment":[30] }, "attributes":["uid ","fk","att1"] }
從 json 解組屬性時出錯:從 json 中解組專案時出錯:json:無法將物件解組為 []*jsonschema.Schema 型別的 Go 值我該如何解決?
uj5u.com熱心網友回復:
架構中的值contains必須是架構:

根據您的問題,也許將“屬性”架構更改為:
"attributes": {
"type": "array",
"minItems": 2,
"items": [ { "const": "fk" }, { "const": "uid" } ],
"additionalItems": {
"type": "string"
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/493494.html
標籤:数组 json 去 jsonschema
上一篇:Base64解碼未完成
