0

我得到一个如下的 JSON 字符串

[
    {
        "id": 20,
        "title": "a",
        "allDay": true,
        "start": "2012-12-04 00:00",
        "end": "2012-12-07 00:00",
        "color": "#eb491d",
        "startDate": "/Date(1354559400000)/",
        "endDate": "/Date(1354818600000)/",
        "Location": "a",
        "StartDatestr": "2012-12-04",
        "EndDatestr": "2012-12-04",
        "StartTime": "00:00",
        "EndTime": "00:00",
        "Alert": false,
        "Repeat": false,
        "RepeatDays": 0,
        "CalendarID": 13,
        "CustomerNo": 593963,
        "CustomerName": "test_apple",
        "IsProspect": true,
        "Description": ""
    }
]

当我检查如下长度时,它返回“1”

console.log(myAppointment.length);

但是当我尝试如下访问时,它会给出未定义的错误。

var myAppointment = JSON.parse(data.d);
sessionStorage.CustomerID = data.CustomerNo;
console.log(sessionStorage.CustomerID);

我不知道。谁能告诉我我在这里缺少什么

4

2 回答 2

2

将解析代码更改为:

var myAppointment = JSON.parse(data.d)[0];
于 2012-12-05T05:44:23.853 回答
0

如下更改第二行:

var myAppointment = JSON.parse(data.d);
sessionStorage.CustomerID = myAppointment.CustomerNo;// from data.CustomerNo
console.log(sessionStorage.CustomerID);

您试图从数据对象访问已解析的片段。

于 2012-12-05T05:41:09.073 回答