我想从下面的对象中获取工作日的值。怎么能得到这个? 我正在获得未定义的值。我也使用JSON.parse,但仍然出现另一个错误。
var timecardDayDetails = [{
"projectId": 'projectName',
"activityId": 'projectActivity',
"location": 'projectLocation',
"taskDetails": 'projectComments',
"workingDay": 'Monday',
"workingDate": "2019-11-04",
"workingHours": 'workingHours',
"startTime": 'tsTimeStart',
"endTime": 'tsTimeEnd',
"status": "draft"
},
{
"projectId": 'projectName',
"activityId": 'projectActivity',
"location": 'projectLocation',
"taskDetails": 'projectComments',
"workingDay": 'Monday',
"workingDate": "2019-11-04",
"workingHours": 'workingHours',
"startTime": 'tsTimeStart',
"endTime": 'tsTimeEnd',
"status": "draft"
}
]
var parsedData = JSON.stringify(timecardDayDetails);
alert(parsedData['workingDay']);
答案 0 :(得分:1)
这是数组,因此您需要定义索引以获取值
modified
然后像t timecardDayDetails[0]
imecardDayDetails[0]['workingDay']