访问JSON值jQuery

时间:2012-06-07 00:25:21

标签: jquery json

我像这样返回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
        });
    }
});

但是得到孩子[0]并没有定义错误。

我哪里错了?

0 个答案:

没有答案