0

我有 JSON 像这样返回:

{
    "response": {
        "2012-07-01": {
            "Variations": [
                {
                    "ID": 293,
                    "InternalItemID": "xyz",
                    "RRP": "50.00",
                    "Price": "40.00",
                    "Available": 65,
                    "RedeemableDate": "2012-07-01"
                },
                {
                    "ID": 107,
                    "InternalItemID": "xxx",
                    "RRP": "50.00",
                    "Price": "10.00",
                    "Available": 15,
                    "RedeemableDate": "2012-07-01"
                },
                {
                    "ID": 200,
                    "InternalItemID": "Item name",
                    "RRP": "50.00",
                    "Price": "40.00",
                    "Available": 65,
                    "RedeemableDate": "2012-07-01"
                }
            ]
        }
    }
}

我需要循环浏览它并访问各种值。

我目前正在尝试这样做:

var calevents = [];
$.each(data.response, function(index,item){
    calDate = index;
    child = item.Variations;
    if ($.isEmptyObject(child) == false){
        calPrice = child[0].Price;
        calID = child[0].ID;
        calAvailable = child[0].Available;
        calevents.push({
            'id': calID,
            'title': buildEventTitle(calAvailable,
                    calDate.substring(calDate.length,calDate.length-2),
                    child[0].Price, calID, child[0].RRP),
            'start': $.fullCalendar.parseDate(calDate),
            'end': $.fullCalendar.parseDate(calDate),
            'allDay': true
        });
    }
});

但我得到 child[0] is not defined 错误。

我哪里错了?

4

0 回答 0