【发布时间】:2020-09-03 18:08:17
【问题描述】:
我有一些变量,值是动态的,但在本例中,我将给出每个变量的固定值。如何将变量放入 JSON 字符串并将其发布到 Web 服务?
String date = java.time.Clock.systemUTC().instant().toString();
String uuid1 = "6f0be90b-db0d-1b03-8a14-aaa70a5d239d";
String uuid2 = "671d2db0-b0d3-2745-9f76-52c22255a4b4";
String val ="1589430997009_658";
这是 JSON 字符串,如何将 currentDateTime 和 uuid1、uuid2 和 urlDocument 替换为我拥有的变量
{
"resourceType": "Bundle",
"type": "transaction",
"meta": {
"lastUpdated": "2018-04-13T08:29:35",
"profile": [
"http://ihe.net/fhir/tag/iti-65"
]
},
"entry": [
{
"resource": {
"resourceType": "DocumentManifest",
"type": {
"coding": [
{
"code": "MPQ",
"display": "MPQ",
"system": "2.16.840.1.113883.5.25"
}
]
},
"status": "current",
"id": "1231010",
"description": "DocumentManifest",
"created": "{{currentDateTime}}",
"masterIdentifier": {
"system": "1.1.1.9.9",
"value": "{{uuid1}}"
},
"content": [
{
"pReference": {
"reference": "DocumentReference/170013"
}
}
],
"subject": {
"reference": "http://xxxx-myedu.online:8081/DataGateway/fhir/dstu3/Patient/1.1.1.99.1.-.d8a08ddc-b1f1-4c86-9bc6-9203914d9e6c"
},
"source": "1.1.1"
}
},
{
"resource": {
"resourceType": "DocumentReference",
"id": "170013",
"status": "current",
"created": "{{currentDateTime}}",
"indexed": "{{currentDateTime}}",
"description": "XXXS_Softpath Report histo",
"masterIdentifier": {
"system": "urn:oid:1.2.3",
"value": "{{uuid2}}"
},
"content": [
{
"attachment": {
"contentType": "application/pdf",
"url": "{{documentUrl}}"
},
"format": [
{
"system": "DEMO_FORMATCODES",
"code": "image",
"display": "DEMO_FORMATCODES"
}
]
}
],
"context": {
"period": {
"start": "{{currentDateTime}}",
"end": "{{currentDateTime}}"
},
"facilityType": {
"coding": [
{
"system": "DEMO_HEALTHCAREFACILITYTYPECODES",
"code": "MP",
"display": "DEMO_HEALTHCAREFACILITYTYPECODES"
}
]
},
"practiceSetting": {
"coding": [
{
"system": "DEMO_PRACTICESETTINGCODES",
"code": "1200",
"display": "DEMO_PRACTICESETTINGCODES"
}
]
},
"sourcePatientInfo": {
"reference": "#thepatient"
}
},
"type": {
"coding": [
{
"system": "DEMO_TYPECODES",
"code": "11111-7",
"display": "DEMO_TYPECODES"
}
]
},
"class": {
"coding": [
{
"system": "DEMO_CLASSCODES",
"code": "11111-1",
"display": "DEMO_CLASSCODES"
}
]
},
"language": "en_US",
"securityLabel": [
{
"coding": [
{
"system": "DEMO_CONFIDENTIALITYCODES",
"code": "N",
"display": "DEMO_CONFIDENTIALITYCODES"
}
]
}
],
"author": [
{
"reference": "#1235555"
}
],
"custodian": [
{
"reference": "#1236666"
}
],
"subject": {
"reference": "http://xxx-mye.online:8081/DataGateway/fhir/dstu3/Patient/1.1.1.99.1.-.d8a08ddc-b1f1-4c86-9bc6-9203914d9e6c"
},
"contained": [
{
"resourceType": "Practitioner",
"id": "1235555",
"name": [
{
"given": [
"Support"
],
"family": [
"Administrator"
]
}
]
},
{
"resourceType": "Organization",
"id": "1236666",
"name": "XXX-MOL",
"identifier": [
{
"use": "official",
"value": "1.1.1.9.9"
}
]
},
{
"resourceType": "Patient",
"id": "#thepatient",
"identifier": [
{
"use": "temp",
"system": "urn:oid:1.1.1.99.1",
"value": "d8a08ddc-b1f1-4c86-9bc6-9203914d9e6c"
},
{
"use": "usual",
"system": "urn:oid:1.1.1.2.2.1",
"value": "PatID-101"
}
],
"name": [
{
"family": "Family-101",
"given": [
"Given-101"
]
}
],
"gender": "male",
"birthDate": "2020-01-01",
"deceasedBoolean": false
}
]
}
}
]
}
我已经尝试使用 String java 中的 replace 函数替换它,也已经尝试使用 JSON Object put,但它不起作用。任何人都可以提供更多建议吗?谢谢你
【问题讨论】:
-
请提供您的代码。
-
一种方法: 1. 将 JSON 字符串解析为其代表的 Java 对象。 2. 根据需要更改此对象的字段。 3. 将 Java 对象字符串化回 JSON 字符串。
-
请以MCVE 的形式分享您的research、attempt,以及为什么it's not working 根据帮助文章How to Ask a Good Question 包括错误消息和/或堆栈跟踪跨度>
标签: java json web-services variables dynamic