【发布时间】:2021-06-10 03:29:51
【问题描述】:
我正在尝试在 Visual Basic 代码中验证 JSON 文件。我一直在寻找有关 Newtonsoft 的文档,但是它们仅提供 C# 中的示例代码。我基本上想使用模式字符串来验证 VB 数据库中的一些 JSON 文件。如果下面的代码(用 C# 编写)是用 VB 编写的,它会是什么样子?
你是怎么写的
JsonSchema schema = JsonSchema.Parse(schemaJson);
在 Visual Basic 代码中?
string schemaJson = @"{
'description': 'A person',
'type': 'object',
'properties':
{
'name': {'type':'string'},
'hobbies': {
'type': 'array',
'items': {'type':'string'}
}
}
}";
JsonSchema schema = JsonSchema.Parse(schemaJson);
JObject person = JObject.Parse(@"{
'name': 'James',
'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
}");
bool valid = person.IsValid(schema);
// true
【问题讨论】:
-
Dim schema as JsonSchema = JsonSchema.Parse(schemaJson)
标签: json vb.net visual-studio json.net schema