jQuery技术:如何加载本地JSON文件?

我试图通过jquery加载本地JSON文件。 代码工作正常但数据在数组中不可用。

$.getJSON("/ajax/data/myjasonfile.json", function(json) { console.log(json); }); 

我的控制台只显示

 Object {data: Array[1]} 

我的样本json

 { "data": [ { "number": "1234", "nameOne": "Laten Thamn", "type": "Fishing Vessels", "flagName": "5467", "buildDate":"12/08/2016" } ] } 

    试试这个来理解你的反应结构。

      $.getJSON("myjasonfile.json", function(json) { console.log(json); // access the response object console.log(json.data); // access the array console.log(json.data[0]); // access the first object of the array console.log(json.data[0].number); // access the first object proprty of the array }); 

    jQuery.getJSON()使用GET HTTP请求从服务器加载JSON编码的数据。

    当您在JSON结构中发布时,可以通过调用json.data来访问该数组:

     $.getJSON("/ajax/data/myjasonfile.json", function(json) { console.log(json.data); // Logs your array }); 

    将json数据存储在数组中:

      $.getJSON("/ajax/data/myjasonfile.json", function(Data) { var array=[]; for(var i=1;i 

    你可以试试这个:

     $.getJSON("test.json", function(json) { console.log(json); // this will show the info it in firebug console }); 

    我想,有些问题在你的路径中调用json文件。 你需要再次检查路径。

    您可以查看以下链接: 加载本地JSON文件

    需要了解更多jQuery教程分享如何加载本地JSON文件?,都可以关注jQuery技术分享栏目---计算机技术网(www.ctvol.com)!

      以上就是jQuery教程分享如何加载本地JSON文件?相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/981775.html

      (0)
      上一篇 2021年12月12日
      下一篇 2021年12月12日

      精彩推荐