PHPスクリプトを使用してJSON文字列を生成しています。これをJavaScriptで使用してデータを表示したいとします。問題は、json.parseを使用した後でもjson文字列データへのアクセスを使用できないことです。私を助けてください。jsonデータを使用できません
JSON文字列は次のとおりです。
{
"8": {
"dept_name": null,
"dept_code": null,
"int_jour": null,
"nat_jour": null,
"inter_nat_conf": null,
"nat_conf": null,
"int_book_chap": null,
"nat_book_chap": null
},
"0": {
"int_jour": 10,
"nat_jour": 1,
"inter_nat_conf": 16,
"nat_conf": 14,
"int_book_chap": 1,
"nat_book_chap": 4,
"dept_code": "101",
"dept_name": "ECE"
},
"1": {
"int_jour": 22,
"nat_jour": 1,
"inter_nat_conf": 32,
"nat_conf": 16,
"int_book_chap": 5,
"nat_book_chap": 0,
"dept_code": "102",
"dept_name": "CSE"
},
"2": {
"int_jour": 12,
"nat_jour": 4,
"inter_nat_conf": 10,
"nat_conf": 23,
"int_book_chap": 1,
"nat_book_chap": 0,
"dept_code": "103",
"dept_name": "IT"
},
"3": {
"int_jour": 21,
"nat_jour": 0,
"inter_nat_conf": 9,
"nat_conf": 35,
"int_book_chap": 0,
"nat_book_chap": 0,
"dept_code": "104",
"dept_name": "EE"
},
"4": {
"int_jour": 13,
"nat_jour": 1,
"inter_nat_conf": 8,
"nat_conf": 33,
"int_book_chap": 0,
"nat_book_chap": 1,
"dept_code": "105",
"dept_name": "MCA"
},
"5": {
"int_jour": 10,
"nat_jour": 5,
"inter_nat_conf": 12,
"nat_conf": 13,
"int_book_chap": 0,
"nat_book_chap": 1,
"dept_code": "106",
"dept_name": "MBA"
},
"6": {
"int_jour": 57,
"nat_jour": 6,
"inter_nat_conf": 5,
"nat_conf": 10,
"int_book_chap": 0,
"nat_book_chap": 1,
"dept_code": "109",
"dept_name": "AS"
},
"7": {
"int_jour": 0,
"nat_jour": 0,
"inter_nat_conf": 0,
"nat_conf": 0,
"int_book_chap": 0,
"nat_book_chap": 0,
"dept_code": "110",
"dept_name": "CIVIL"
}
}
ジャバスクリプトは次のようになります。
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
document.getElementById("demo").innerHTML = myObj.[1].dept_name;
}
};
xmlhttp.open("GET", "sss.php", true);
xmlhttp.send();
</script>
どのようなエラーが表示されますか? –