簡體   English   中英

json使用Powershell中的json模式進行驗證

[英]json validate with json schema in powershell

這是我的代碼,用於在Powershell中使用jsonschema驗證json。 和它的錯誤與以下錯誤消息。

找不到“ Validate”和參數計數:“ 2”的重載。

$json =   Get-Content -Raw -Path C:\temp\locationstores.json
$SchmeaJson = Get-Content -Raw -Path C:\temp\LocationstoreSchema.json
NewtonsoftJsonAssembly =  [Reflection.Assembly]::LoadFile("C:\temp\Json100r3\Bin\net45\Newtonsoft.Json.dll")
$NewtonsoftJsonSchemaAssembly =  [Reflection.Assembly]::LoadFile("C:\temp\JsonSchema30r3\Bin\net45\NewtonSoft.Json.Schema.dll")
Add-Type -Path "C:\temp\JsonSchema30r3\Bin\net45\NewtonSoft.Json.Schema.dll" 
Add-Type -Path "C:\temp\Json100r3\Bin\net45\Newtonsoft.Json.dll"
[Newtonsoft.Json.Schema.SchemaExtensions]::Validate([Newtonsoft.Json.Linq.JToken]::Parse($json), [Newtonsoft.Json.Schema.JSchema]::Parse($SchmeaJson))

請讓我知道錯誤是什么,以及使用powershell中的json模式驗證json的任何其他方法。

您可以嘗試其他方法調用:

示例C#代碼以適應:

public void ValidateWithOutEventHandlerFailure()
{
        //...
        JsonSchema schema = JsonSchema.Parse("{'pattern':'lol'}");
        JToken stringToken = JToken.FromObject("pie");
        stringToken.Validate(schema);

來源: https ://github.com/JamesNK/Newtonsoft.Json/blob/aa5f28c09732db5fb3e316433547ea7cdecd8804/Src/Newtonsoft.Json.Tests/Schema/ExtensionsTests.cs上的JSON.NET單元測試

暫無
暫無

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

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