繁体   English   中英

如何从JSON解析DiagnosticReport并再次打印相同的JSON?

[英]How to parse a DiagnosticReport from a JSON and print the same JSON again?

我正在从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);

由于不显示 观察结果中的文本标签,结果有所不同

{
  "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"
    }
  ]
}

我正在尝试此操作,因为我的软件生成了DiagnosticReport,并且需要将其完全打印在JSON文件中。

谢谢你的帮助!!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM