gpt4 book ai didi

jquery - jquery ajax读取特定的json值

转载 作者:行者123 更新时间:2023-12-01 07:11:41 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com