我正在尝试使用JSON架构验证。我在JSON.NET Help page上使用模式的基本示例。我得到了例外
System.MethodAccessException: Attempt by method
'Newtonsoft.Json.Schema.JSchema.Parse(System.String)' to access method
'Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(System.Object, System.String)' failed
我的代码在
下面[TestMethod]
public void prettySimple()
{
string schemaJson = @"{
'type': 'object',
'properties': {
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}";
JSchema schema = JSchema.Parse(schemaJson);
}
答案 0 :(得分:1)
听起来像Newtonsoft.Json和Newtonsoft.Json.Schema之间的软件包不匹配。
Newtonsoft.Json.Schema依赖于Newtonsoft.Json版本> = 6.0.8。因此,请确保它在您的项目中是最新的。
我首先安装了Newtonsoft.Json,然后架构包和代码运行正常。
我的包配置:
<packages>
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="Newtonsoft.Json.Schema" version="1.0.8" targetFramework="net45"/>
</packages>