我有这样的代码...

function diagnoseprint() {
document.getElementById('goeshere').innerHTML=localStorage['timetable'];
var decode = JSON.parse(localStorage['timetable']);
var step = decode.timetable.UCFF1201ENG.2;
document.getElementById('goeshere').innerHTML=step[1];}


并且localStorage ['timetable']实际上是500KB的东西,我不打算在这里全部张贴,我在其中张贴一点...

{"meta":{"week":"2012-02-13","lastsync":"1329415763","jsontime":1329456671},"timetable":{"TPMF1101MBA":{"1":["MON,13-Feb-12","08:45 - 10:15","L2 - 12","TPM","BSB20133-M-BRM-L","DR. TAN JUAT HONG"],"2":["WED,15-Feb-12","10:35 - 12:05","L2 - 12","TPM","BSB20133-M-BRM-T","DR. TAN JUAT HONG"]},


我不知道为什么我不能提取那一点,顺便说一句,我刚开始使用JavaScript。

最佳答案

代替:

var step = decode.timetable.UCFF1201ENG.2;


采用:

var step = decode.timetable.UCFF1201ENG[2];


2不是有效的标识符,因此不能在点表示法中使用。使用括号表示法,它的作用完全相同。

10-07 19:02