C# 带ISO8601的三元组在dotnetrdf中断开RDFJSON解析器的日期

C# 带ISO8601的三元组在dotnetrdf中断开RDFJSON解析器的日期,c#,json,parsing,rdf,dotnetrdf,C#,Json,Parsing,Rdf,Dotnetrdf,我试图在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/

我试图在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规定的日期和时间组合表达式,那么问题就会解决。例如,只有日期起作用。 这感觉像是一个bug,还是一个配置问题

我的套餐参考资料如下:

<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#的初学者,我的调试技能有些不稳定,所以我只能猜测


非常感谢您提供任何形式的指导。

您的分析是正确的-Newtonsoft解析器正在帮助您将ISO日期格式转换为日期对象。可以禁用Newtonsoft解析器的功能,我们的RdfJsonParser可能应该禁用它,因为我们不希望字符串转换为日期对象

不幸的是,我不认为有一种方法可以从代码中实现这一点——这是dotNetRDF本身所需要的修复。我已将此作为dotNetRDF问题跟踪器记录


编辑:现在应该在2.0.0-pre0009中修复此问题。您的分析是正确的-Newtonsoft解析器正在帮助将ISO日期格式转换为日期对象。可以禁用Newtonsoft解析器的功能,我们的RdfJsonParser可能应该禁用它,因为我们不希望字符串转换为日期对象

不幸的是,我不认为有一种方法可以从代码中实现这一点——这是dotNetRDF本身所需要的修复。我已将此作为dotNetRDF问题跟踪器记录


编辑:这应该在2.0.0-pre0009中得到修复

Json.Net不会“尝试变得聪明”。这是意料之中的行为。如果不是这样的话,网络开发者会反抗。如果您不想解析字段,可以告诉它以字符串形式读取字段,在目标类上使用属性,或者设置为Json。Net不会“尝试变得聪明”。这是意料之中的行为。如果不是这样的话,网络开发者会反抗。如果不想解析字段,可以告诉它以字符串形式读取字段,在目标类上使用属性,或者设置为,看起来只需要在CommentIgnoringJsonTextReader的构造函数中设置
DateParseHandling=DateParseHandling.None
?似乎没有办法向
RdfJsonParser
注入已配置的读取器或任何其他设置,看起来只需要在CommentIgnoringJsonTextReader的构造函数中设置
DateParseHandling=DateParseHandling.None
?似乎没有办法向
RdfJsonParser