搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JSON 教程
JSON 基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>JSON.parse() JSON格式内容转为JavaScript数组示例 - 基础教程(div.cn)</title> <body> <p>将以JSON数组编写的内容将转换为JavaScript数组:</p> <p id="output"></p> <p>See <a href="json_array.txt">json_array.txt</a></p> <script> var httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function() { if (this.readyState === 4 && this.status === 200) { var myArr = JSON.parse(this.responseText); document.getElementById("output").innerHTML = myArr[0]; } }; httpRequest.open("GET", "json_array.txt", true); httpRequest.send(); </script> </body> </html>
运行结果