【问题标题】:Parsing JSON Schema using Json.NET schema throws error System.MethodAccessException使用 Json.NET 架构解析 JSON 架构会引发错误 System.MethodAccessException
【发布时间】:2015-02-25 23:38:11
【问题描述】:

我正在尝试使用 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);
    }

【问题讨论】:

  • 你引用的是Newtonsoft.Json.Schema吗?
  • 是的,我是。还引用 Newtonsoft.Json.Schema

标签: c# json json.net jsonschema


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多