簡體   English   中英

枚舉的JSON模式驗證兩次顯示相同的錯誤消息

[英]JSON schema validation for enum shows same error message twice

我正在提交以下JSON字符串:

{
    "companyName" : "Goog"
}

該架構為:

{
    "companyName": { 
        "type":[ "string", "null" ], 
        "description": "Companies list", 
        "required":false ,
        "maxLength": 256,
        "enum": [ "Google", "Apple" , null ]
    }
}

我使用Newtonsoft.Json驗證程序函數IsValid

JObject jobj= _jsonParser.ToJSonObject(jsonString);
IList<string> errMessages;
var valid = jobj.IsValid(jsonSchema, out errMessages);

當我驗證時,我得到相同的錯誤消息重復兩次:

Value "Goog" is not defined in enum. Line 34,
 position 35.,
Value "Goog" is not defined in enum. Line 34,
 position 35.

我的工作有問題嗎? 還是JSON驗證程序有問題?

對於收到的錯誤消息,我將其放在列表中並稱為distinct()

errMessages.Distinct().ToList()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM