计科知识库
  • 源界面
  • 博客圈
  • 专题
  • 博友
  • 登录
  • 注册
源界面 源界面 1个月前

以下函数从文件中读取JSON数据

js
  1. function getJsonData(){
  2. var xhttp = new XMLHttpRequest();
  3. xhttp.onreadystatechange = function (){
  4. if(xhttp.readyState == 4 && xhttp.status == 200){
  5. var javaobj = JSON.parse(xhttp.response);
  6. return javaobj;
  7. }
  8. }
  9. xhttp.open("GET", "json_output.json", true)
  10. xhttp.send();
  11. }

json_output.json

  1. {"name":"John Doe","age":30,"email":"john@example.com"}
  • © 2025 源界面 源码为笔,博客为路,写就数字未来
  • 建议
  • 图片压缩
  • | 鄂ICP备14016484号-6

    鄂公网安备 42068402000140