在我将 GET 请求发送到休息 api 后,我有以下 json 作为 responseText 返回:
{
"ehrs": [
{
"uid": "11111111-1111-1111-1111-111111111111",
"dateCreated": "2017-09-21 04:36:47",
"subjectUid": "11111111-1111-1111-1111-111111111111",
"systemId": "CABOLABS_EHR_SERVER",
"organizationUid": "123456"
},
{
"uid": "22222222-1111-1111-1111-111111111111",
"dateCreated": "2017-09-21 04:36:47",
"subjectUid": "22222222-1111-1111-1111-111111111111",
"systemId": "CABOLABS_EHR_SERVER",
"organizationUid": "123456"
},
{
"uid": "33333333-1111-1111-1111-111111111111",
"dateCreated": "2017-09-21 04:36:48",
"subjectUid": "33333333-1111-1111-1111-111111111111",
"systemId": "CABOLABS_EHR_SERVER",
"organizationUid": "123456"
},
{
"uid": "44444444-1111-1111-1111-111111111111",
"dateCreated": "2017-09-21 04:36:48",
"subjectUid": "44444444-1111-1111-1111-111111111111",
"systemId": "CABOLABS_EHR_SERVER",
"organizationUid": "123456"
},
{
"uid": "55555555-1111-1111-1111-111111111111",
"dateCreated": "2017-09-21 04:36:48",
"subjectUid": "55555555-1111-1111-1111-111111111111",
"systemId": "CABOLABS_EHR_SERVER",
"organizationUid": "123456"
},
{
"uid": "97fecfa9-d51c-440f-93eb-cb8bbabc5cdc",
"dateCreated": "2017-09-27 22:53:55",
"subjectUid": "ef70c3bf-8aba-4f4b-83b7-097f2aff60f6",
"systemId": "CABOLABS_EHR_SERVER",
"organizationUid": "123456"
},
{
"uid": "4e363a7c-0b25-405c-93d8-1361f4775ccd",
"dateCreated": "2017-10-10 06:08:58",
"subjectUid": "228084fb-10d8-4441-8683-aad526e2c5fd",
"systemId": "CABOLABS_EHR_SERVER",
"organizationUid": "123456"
},
{
"uid": "3c6b8a98-1488-427b-8251-5bebad35afda",
"dateCreated": "2017-10-10 21:03:44",
"subjectUid": "3dd3a7b1-b642-4e9b-b12a-4fcd10af6e4f",
"systemId": "CABOLABS_EHR_SERVER",
"organizationUid": "123456"
}
],
"pagination": {
"max": 10,
"offset": 0,
"nextOffset": 10,
"prevOffset": 0
},
"timing": "0 ms"
}
我想从这个json的所有“ehrs”元素中只获取“uid”和“dateCreated”元素,然后以适当的方式显示它们,同时显示属性名称及其值。我尝试了以下代码:
var ehrjson = (this.responseText);
var ehrobj = JSON.parse(ehrjson);
document.getElementById("ehrlist").innerHTML = ehrobj.ehrs.uid+" ---- "+ehrobj.ehrs.dateCreated+"\n";
但它显示 [undefined] ---- [undefined] 作为 html 中的输出。我也有一种感觉,我的代码是错误的,但不知道该怎么做。如何解决这个问题?