我正在尝试在 dotnetrdf 的帮助下解析 RDF/JSON 图,当我将日期作为文字时它会失败,下面是一些示例代码,其中包含导致问题的有问题的三元组。
using VDS.RDF;
using VDS.RDF.Parsing;
...
var jsonstr = @"
{
""http://example.com"": {
""http://purl.org/dc/terms/issued"": [{
""datatype"": ""http://www.w3.org/2001/XMLSchema#date"",
""type"": ""literal"",
""value"": ""2017-10-24T15:01:53+02:00""
}]
}
}";
IGraph g = new Graph();
g.LoadFromString(str1, new RdfJsonParser());
导致以下异常:
Exception has occurred: CLR/VDS.RDF.Parsing.RdfParseException
Exception thrown: 'VDS.RDF.Parsing.RdfParseException' in dotNetRDF.dll: '[Line 4 Column 40 to Line 7 Column 44] Unexpected Token 'Date' encountered, expected a Property Value describing one of the properties of an Object Node'
at VDS.RDF.Parsing.RdfJsonParser.Error(JsonParserContext context, String message, PositionInfo startPos)
at VDS.RDF.Parsing.RdfJsonParser.ParseObject(JsonParserContext context, INode subj, INode pred)
at VDS.RDF.Parsing.RdfJsonParser.ParseObjectList(JsonParserContext context, INode subj, INode pred)
at VDS.RDF.Parsing.RdfJsonParser.ParsePredicateObjectList(JsonParserContext context, INode subj)
at VDS.RDF.Parsing.RdfJsonParser.ParseTriples(JsonParserContext context)
at VDS.RDF.Parsing.RdfJsonParser.ParseGraphObject(JsonParserContext context)
at VDS.RDF.Parsing.RdfJsonParser.Parse(IRdfHandler handler, TextReader input)
at VDS.RDF.Parsing.RdfJsonParser.Load(IRdfHandler handler, TextReader input)
at VDS.RDF.Parsing.StringParser.Parse(IGraph g, String data, IRdfReader reader)
如果我删除显式数据类型,问题是一样的。但是,如果我更改文字,问题就会消失,因此它不再是根据 ISO8601 的组合日期和时间表达式。例如,只有日期有效。这感觉像是一个错误,还是配置问题?
我的包参考是:
<PackageReference Include="dotnetrdf" Version="1.0.12" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="VDS.Common" Version="1.8.0" />
我的猜测是底层的 JSON 解析器(Newtonsoft)试图变得聪明,并将字符串检测为可以转换为日期对象的东西。由于我是 C# 的初学者,我的调试技巧有些不稳定,所以我一直在猜测。
任何形式的指导都将受到高度赞赏。