如何加载本地JSON文件? [英] How to load a local JSON file?

查看:832
本文介绍了如何加载本地JSON文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to load a Local JSON file by jquery. the code works fine but the data are not available in array.

$.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"
        }
    ]
}


推荐答案

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

Try this to understand your response structure.

 $.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
    });

这篇关于如何加载本地JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆