首页 > 解决方案 > 如何将 JSON 文件转换为数组列表

问题描述

我想将我的 JSON 文件转换为一个数组列表,然后我可以访问并使用它来显示网页上的信息。

我的 html 文件

var xmlhttp = new XMLHttpRequest();
 xmlhttp.onreadystatechange = function() {
 if(this.readyState == 4 && this.status == 200) {
    console.log(JSON.parse(this.responseText))
}
};
 xmlhttp.open("GET", "PATIENT51.txt", true);
 xmlhttp.send(); 

我的 JSON 文件

{
“resourceType”:”RiskAssessment”,
“Notes”: [
{“date”: “05/13/2019”, “note”: “my notes”},
{“date”: “02/22/2018”, “note”: “cool”}
]
}

如何访问05/13/2019,我尝试使用

myObj.Notes[0].note;

但结果是“未定义”,我希望能够使用日期制作表格——每个日期都会有一个与之关联的注释。

标签: javascriptjson

解决方案



推荐阅读