0

我正在从 JSON 文件解析 DiagnosticReport 并且它工作正常,但是当我尝试通过 IParser 编码函数打印相同的 JSON 文件时,JSON 与原始文件不同。我需要打印相同的 JSON。

原始 JSON(字符串 json)

    {
  "resourceType": "DiagnosticReport",
  "text": {
    "status": "generated",
    "div": "<div><p><b>Narrative A</b></p></div>"
  },
  "contained": [
    {
      "resourceType": "Patient",
      "id": "1"
    },
    {
      "resourceType": "Observation",
      "id": "2",
      "meta": {
        "lastUpdated": "2017-03-22T22:00:28.089-05:00"
      },
      "text": {
        "div": "<div><p><b>Narrative B</b></p></div>"
      },
      "comment": "a comment"
    }
  ],
  "status": "appended",
  "code": {
    "coding": [
      {
        "code": "Report01"
      }
    ]
  },
  "subject": {
    "reference": "#1"
  },
  "effectiveDateTime": "2017-03-22T22:00:28-05:00",
  "issued": "2017-03-22T22:00:28.070-05:00",
  "result": [
    {
      "reference": "#2"
    }
  ]
}

第一步是解析,第二步是编码和打印

DiagnosticReport report = parser.parseResource(DiagnosticReport.class, json);
String encodeJSON = parser.encodeResourceToString(report);
System.out.println(encodeJSON);

结果不一样,因为Observation中的文本标签没有显示出来

{
  "resourceType": "DiagnosticReport",
  "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Narrative A</b></p></div>"
  },
  "contained": [
    {
      "resourceType": "Patient",
      "id": "1"
    },
    {
      "resourceType": "Observation",
      "id": "2",
      "meta": {
        "lastUpdated": "2017-03-22T22:00:28.089-05:00"
      },
      "comment": "a comment"
    }
  ],
  "status": "appended",
  "code": {
    "coding": [
      {
        "code": "Report01"
      }
    ]
  },
  "subject": {
    "reference": "#1"
  },
  "effectiveDateTime": "2017-03-22T22:00:28-05:00",
  "issued": "2017-03-22T22:00:28.070-05:00",
  "result": [
    {
      "reference": "#2"
    }
  ]
}

我正在尝试这个,因为我的软件生成了一个诊断报告,我需要将它完全打印在一个 JSON 文件中。

谢谢你的帮助!!

4

1 回答 1

2

在包含的资源中拥有叙述是不合法的,拥有 meta/lastUpdated 也是不合法的。存在禁止两者的不变量。理想情况下,解析软件应该抛出异常,但是序列化程序在序列化不应该存在的内容时遇到问题也就不足为奇了。

查看dstu3dstu2中的 dom-1 和 dom-4

于 2017-03-26T16:43:40.910 回答