Jquery $.getJSON中的函数参数是如何工作的?

Jquery $.getJSON中的函数参数是如何工作的?,jquery,ajax,json,jquery-mobile,getjson,Jquery,Ajax,Json,Jquery Mobile,Getjson,是否有官方文件解释函数参数是如何工作的 $.getJSON("files/golfClubs.json", function (data) { $.each(data, function (index, value) { $("#filtermenu").append("<option value='" + data[0].GolfCourses[index].GolfCourseID + "'>" + data[0].GolfCourses[index].G

是否有官方文件解释函数参数是如何工作的

$.getJSON("files/golfClubs.json", function (data) {
    $.each(data, function (index, value) {
        $("#filtermenu").append("<option value='" + data[0].GolfCourses[index].GolfCourseID + "'>" + data[0].GolfCourses[index].GolfCourseName + "    </option>");
    });
});
问题1:我想知道当引用同一个参数变量时,参数基本上是如何传递数据的。尤其是嵌套jSON。当传递两个参数而不是一个参数时会发生什么

问题2:与函数中的参数一起,使用下面的JSON,如何访问GolfCourses.GolfCourseBookings.DayBookings

[
    {
        "GolfClubID": "TROPICANA",
        "GolfClubName": "Tropicana Golf and Country Club",
        "GolfCourses": [
            {
                "GolfCourseID": "1",
                "GolfCourseName": "West Course - 1st 9",
                "GolfCourseBookings": [
                    {
                        "DayNumber": 1,
                        "DayDate": "19/03/2014",
                        "DayBookings": [
                            {
                                "TimeSlotID": "0",
                                "Time" : "07:00",
                                "Class": "Closed"
                            },
                            {
                                "TimeSlotID": "1",
                                "Time" : "07:10",
                                "Class": "Closed"
                            },
                            {
                                "TimeSlotID": "2",
                                "Time" : "07:20",
                                "Class": "Closed"
                            },
请阅读

这里有一个对象(数据)数组,可以看出这一点,因为在javascript中:

[]=阵列, {}=对象

例如:

$.getJSON("files/golfClubs.json", function (data) {
    alert(data);
//Returns undefined. Unless .JSON.stringify-ed().
});
var GolfCourses = []; // Array
var GolfCourses = new Array(); // Array

var GolfCourse = {}; // Object
var GolfCourse = new Object(); // Object
因此,要回答您的问题:

Q1.$。getJSON重新运行“数据”中的所有内容。因此,如果您想从服务器发送两个参数,例如name=“John”和last_name=“Travolta”,则可以使用javascript对象表示法(JSON)发送:

在客户端,您可以这样访问它:

data.name; // John
data.last_name; // Travolta
如果希望服务器发送各种对象:

data = [
    { "name": "John",
      "last_name": "Travolta" },
    { "name": "James",
      "last_name": "Dean" }
];
您可以访问:

data[1].last_name; // Dean
问题2。基本上:

data[0].GolfCourses[0].GolfCouseBookings[0].DayBookings[0].Class; // Closed

Google“JSON或Javascript对象表示法”获取信息。

您的数据是嵌套的数组对象,因此您可以访问数据,如警报(数据[0])
value[0]。GolfCourses[index]。GolfCourseID
数据[0]……。
data[0].GolfCourses[0].GolfCouseBookings[0].DayBookings[0].Class; // Closed