简体   繁体   English

Newtonsoft.Json.Schema.JsonSchema已经过时了?

[英]Newtonsoft.Json.Schema.JsonSchema is obsolete?

I'm trying to create a method to validate a Json string with a Json schema using this method: http://www.newtonsoft.com/json/help/html/JsonSchema.htm 我正在尝试使用此方法创建一个使用Json模式验证Json字符串的方法: http//www.newtonsoft.com/json/help/html/JsonSchema.htm

It says the object is obsolete and moved to its own package, so I use NuGet and install the package ( Newtonsoft.Json.dll and Newtonsoft.Json.Schema.dll are references) and have: 它说该对象已经过时并移动到它自己的包中,所以我使用NuGet并安装包( Newtonsoft.Json.dllNewtonsoft.Json.Schema.dll是引用)并具有:

using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Linq;

    public bool validateSchema(string _Json)
    {
        JsonSchema schema = JsonSchema.Parse(
                        @"{
                            'properties': {
                                [MySchemaHere]
                        }
                        ");
        JObject jobject = JObject.Parse(_Json);

        return jobject.IsValid(schema);
    }

How do I get rid of the obsolete message? 如何摆脱过时的消息? It sounds to me like the code has been moved to the other package/dll, but is called/used in the same way and I'm somehow referencing the obsolete one? 听起来像代码已被移动到其他包/ dll,但以相同的方式调用/使用,我以某种方式引用过时的代码? This seems like I'm missing something simple/obvious. 这似乎我错过了一些简单/明显的东西。

EDIT: Here's an image that might help. 编辑:这是一个可能有用的图像。

http://i.imgur.com/PWwpGRx.png

I finally just created a new project and copied/pasted their example and I see my painfully obvious mistake that I've been fighting with. 我终于创建了一个新项目并复制/粘贴了他们的例子,我看到了我一直在与之斗争的痛苦明显的错误。

I should be using: 我应该用:

JSchema JSchema

and not 不是

JsonSchema JsonSchema

Are you sure that you have this dll? 你确定你有这个dll吗? ,your problem seems to be this JSON Schema validation has been moved to its own package , check more info here: ,您的问题似乎是这个JSON Schema验证已被移动到自己的包中 ,请在此处查看更多信息:

http://www.newtonsoft.com/json/help/html/N_Newtonsoft_Json_Schema.htm http://www.newtonsoft.com/json/help/html/N_Newtonsoft_Json_Schema.htm

Hope this help 希望这有帮助

My problem got resolved when I added a new NuGet Package after searching for "JSON.net schema", which resulted in showing another Newtonsoft.Json.Schema Package in option: 我在搜索“JSON.net schema”后添加了一个新的NuGet包时解决了我的问题,导致在选项中显示另一个Newtonsoft.Json.Schema包:

Tools > Nuget Package Manager > Manage Nuget Packages for Solution 工具> Nuget包管理器>管理解决方案的Nuget包

在此输入图像描述

After doing this, change JSONSchema object to JSchema object. 执行此操作后,将JSONSchema对象更改为JSchema对象。 This will remove the obsolete message and compile the code properly as well. 这将删除过时的消息并正确编译代码。

after: 后:

string schemaJson = @"{
  'description': 'A person',
  'type': 'object',
  'properties':
  {
    'name': {'type':'string'},
    'hobbies': {
      'type': 'array',
      'items': {'type':'string'}
    }
  }
}";

change: 更改:

            JsonSchema schema = JsonSchema.Parse(schemaJson); 

to

            JSchema schema = JSchema.Parse(schemaJson); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM