【发布时间】:2018-04-21 17:29:35
【问题描述】:
我有简单的 JSON 对象和 JSON 模式。 JSON 对象属性名称为字符串。在模式中我期待整数。 IsValid 方法返回 true。我认为它应该返回 false,因为存在类型不匹配。我错过了什么?
//json
var hero = new Hero();
hero.Name = "Egid Beyond Meta";
hero.BattleRank = 5000;
var output = JsonConvert.SerializeObject(hero);
var deserialized = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(output);
// schema
string schema = @"{
'title' : 'Hero',
'type' : 'object',
'Name' : {'type' : 'integer'},
'BattleRank' : {'type' : 'integer'},
required: [ 'Name', 'BattleRank']
}";
var jsonSchema = JSchema.Parse(schema);
// returns ture
Console.WriteLine("is valid " + deserialized.IsValid(jsonSchema));
Console.ReadLine();
【问题讨论】:
标签: c# json json.net jsonschema