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
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:
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? This seems like I'm missing something simple/obvious.
EDIT: Here's an image that might help.
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
and not
JsonSchema
Are you sure that you have this dll? ,your problem seems to be this JSON Schema validation has been moved to its own package , check more info here:
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:
Tools > Nuget Package Manager > Manage Nuget Packages for Solution
After doing this, change JSONSchema object to JSchema object. 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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.