使用 FHIR .net API ( https://github.com/ewoutkramer/fhir-net-api ) 我正在尝试解析 XML 文件,然后将其序列化为 JSON。
Bundle inputBundle = FhirParser.ParseBundleFromXml(inputStream);
Console.WriteLine(FhirSerializer.SerializeBundleToJson(inputBundle));
第一行工作正常,我可以看到捆绑包的 XML 文件已被解析并位于“inputBundle”对象中。
但是,当我将其序列化为 JSON(第二行代码)时,出现错误
System.ArgumentException: Can not add property resourceType to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.
at Newtonsoft.Json.Linq.JObject.ValidateToken(JToken o, JToken existing)
at Newtonsoft.Json.Linq.JContainer.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
at Newtonsoft.Json.Linq.JObject.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
at Newtonsoft.Json.Linq.JContainer.AddInternal(Int32 index, Object content, Boolean skipParentCheck)
at Newtonsoft.Json.Linq.JContainer.Add(Object content)
at Hl7.Fhir.Serialization.JsonDomFhirWriter.WriteStartProperty(String name) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\JsonDomFhirWriter.cs:line 42
at Hl7.Fhir.Serialization.ComplexTypeWriter.write(ClassMapping mapping, Object instance, PropertyMapping prop, SerializationMode mode) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\ComplexTypeWriter.cs:line 75
at Hl7.Fhir.Serialization.ComplexTypeWriter.Serialize(ClassMapping mapping, Object instance, SerializationMode mode) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\ComplexTypeWriter.cs:line 48
at Hl7.Fhir.Serialization.ResourceWriter.Serialize(Object instance, Boolean contained) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\ResourceWriter.cs:line 35
at Hl7.Fhir.Serialization.BundleJsonSerializer.getContentsAsJObject(Resource resource, Boolean summary) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\BundleJsonSerializer.cs:line 141
at Hl7.Fhir.Serialization.BundleJsonSerializer.createEntry(BundleEntry entry, Boolean summary) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\BundleJsonSerializer.cs:line 94
at Hl7.Fhir.Serialization.BundleJsonSerializer.WriteTo(Bundle bundle, JsonWriter writer, Boolean summary) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\BundleJsonSerializer.cs:line 43
at Hl7.Fhir.Serialization.FhirSerializer.<>c__DisplayClassd.<SerializeBundleToJson>b__c(JsonWriter jw) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\FhirSerializer.cs:line 115
at Hl7.Fhir.Serialization.FhirSerializer.jsonWriterToString(Action`1 serializer) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\FhirSerializer.cs:line 198
at Hl7.Fhir.Serialization.FhirSerializer.SerializeBundleToJson(Bundle bundle, Boolean summary) in D:\BENBUN_CODE\FHIR\fhir-net-api-client-DSTU-update\src\Hl7.Fhir.Api\Serialization\FhirSerializer.cs:line 115
at fhirjx.Program.processFiles() in C:\Users\RichardKavanagh\documents\visual studio 2010\Projects\fhirjx\fhirjx\Program.cs:line 121
有关信息,我使用的 XML 文件直接取自http://www.hl7.org/implement/standards/fhir/query-example-response.xml.html
有什么想法有什么问题吗?