jquery - jquery ajax读取特定的json值

标签 jquery ajax json

我有一个 JSON 文件,我必须从 json 中读取全名

[{
        "id": 2,
        "username": "admin",
        "firstname": "Stella",
        "lastname": "Cristy",
        "fullname": "Stella Cristy",
        "email": "email0.s@gmail.com",
        "department": "",
        "firstaccess": 12121212,
        "lastaccess": 14101499879,
        "description": "",
        "descriptionformat": 1,
        "country": "IN",
        "profileimageurlsmall": "http:\/\/ddd\/lms\/dd.php\/5\/user\/icon\/f2",
        "profileimageurl": "http:\/\ddd\/lms\/pluginddddfile.php\/5\/user\/icon\/f1",
        "groups": [],
        "roles": [{
            "roleid": 5,
            "name": "",
            "shortname": "student",
            "sortorder": 0
        }],
        "preferences": [{
            "name": "assign_filter",
            "value": "notsubmitted"
        }],
        "enrolledcourses": [{
            "id": 14,
            "fullname": "DIGITAL LOGIC LABORATORY",
            "shortname": "CSEB111(P)"
        }, {
            "id": 4,
            "fullname": "COMPUTATIONAL MATHEMATICS -I",
            "shortname": "CSEB101 "
        }]
    }]

从上面的 json 我想获取全名,我尝试过但没有获取全名。

我的jquery代码是

 $.ajax({
                     url: "url",
                     dataType: "json",
                     type: "POST",
                     success: function(data) {
                 var json = $.parseJSON(data);
                 console.log(json.fullname);
                     }
            });

错误是TypeError: json is null 如何从上面的json中获取全名

最佳答案

这是一个数组,因此要获取第一个数组成员的全名,您必须执行以下操作:

json[0].fullname

关于jquery - jquery ajax读取特定的json值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25801449/

相关文章:

jquery - 带有下一个/上一个链接的简单循环幻灯片

jquery - 如何制作标题全屏背景?

javascript - 如何在javascript中将json转换为数组对象?

javascript - 加载ajax内容时如何更改根页面的页面标题?

jquery - 一点一点地加载页面

jquery - 谷歌日历时区问题

python - 替换 JSON 文件中的字符串

jquery - 按值订购 DIV 用户名 值范围内

jquery - Rails UJS 在 IE 中渲染 js.erb 模板

c# - JavaScriptSerializer.Deserialize() 如果无法解析属性则跳过它