简体   繁体   English

在for循环控制(JSON)之后的SyntaxError:missing)

[英]SyntaxError: missing ) after for-loop control(JSON)

Below is JSON , i try to go through the arrays from 1 to 4, and firebug return me error 下面是JSON,我尝试从1到4遍历数组,并且firebug返回错误

SyntaxError: missing ) after for-loop control
[Break On This Error]   

for( x in LGIntake.corpCodeOptions.marketSegment.1){

StartI...aseId=0 (line 675, col 50)

LGIntake = {};
LGIntake.corpCodeOptions = {};
LGIntake.corpCodeOptions.marketSegment = {
"1":[["FEP","FEP"],["HA","HA"],["HWB","HWB"],["JG","JG"],["LG","LG"],
     ["MAC","MAC"],["NAC","NAC"],["NAL","NAL"],["NAP","NAP"],["NAU","NAU"]],
"2":[["ERS","ERS"],["FEP","FEP"],["HRP","HRP"],["LGC","LGC"],["LGL","LGL"],
     ["MGC","MGC"],["MGL","MGL"],["NAC","NAC"],["NAP","NAP"],["NPB","NPB"],
     ["NPH","NPH"],["NPI","NPI"],["NPP","NPP"],["NPR","NPR"],["NPS","NPS"],
     ["NRSG","NRSG"],["SRK","SRK"],["TAC","TAC"],["TCF","TCF"],["TCI","TCI"],
     ["THE","THE"],["TRS","TRS"]],
"3":[["AFG","AFG"],["ALI","ALI"],["APS","APS"],["FEP","FEP"],["HSC1","HSC1"],
     ["HSC2","HSC2"],["LAN","LAN"],["LGN","LGN"],["NAP","NAP"],["PAK","PAK"],
     ["PSA","PSA"],["RA","RA"],["RC","RC"]],
"4":[["COMA","COMA"],["FEP","FEP"],["LG","LG"],["NAC","NAC"],["NAP","NAP"],
     ["NRMM","NRMM"],["NRSG","NRSG"],["ORAA","ORAA"]]
}; 

and my javascript code 和我的javascript代码

function initMarketSegment(corpCode){
    var corpCodeList = new Array();
    if(corpCode == "1"){
        for( x in LGIntake.corpCodeOptions.marketSegment.1){
            marketSegment.option[marketSegment.option.length] = new Option('LGIntake.corpCodeOptions.marketSegment.1[x]','LGIntake.corpCodeOptions.marketSegment.1[x]');
        }
    }
    else if(corpCode == "2"){
        for( x in LGIntake.corpCodeOptions.marketSegment.2){
            marketSegment.option[marketSegment.option.length] = new Option('LGIntake.corpCodeOptions.marketSegment.2[x]','LGIntake.corpCodeOptions.marketSegment.2[x]');
        }
    }
    else if(corpCode == "3"){
        for( x in LGIntake.corpCodeOptions.marketSegment.3){
            marketSegment.option[marketSegment.option.length] = new Option('LGIntake.corpCodeOptions.marketSegment.3[x]','LGIntake.corpCodeOptions.marketSegment.3[x]');
        }
    }
    else if(corpCode == "4"){
        for( x in LGIntake.corpCodeOptions.marketSegment.4){
            marketSegment.option[marketSegment.option.length] = new Option('LGIntake.corpCodeOptions.marketSegment.4[x]','LGIntake.corpCodeOptions.marketSegment.4[x]');
        }   
    }
}

According to the EMCAScript 5.1 specification, javascript identifiers cannot start with a number. 根据EMCAScript 5.1规范,javascript标识符不能以数字开头。 So the "1" property is not a valid identifier in your JSON. 因此“1”属性不是JSON中的有效标识符。 However, you could reference it as LGIntake.corpCodeOptions.marketSegment[1] . 但是,您可以将其引用为LGIntake.corpCodeOptions.marketSegment[1]

See http://mathiasbynens.be/notes/javascript-identifiers#valid-identifier-names for details. 有关详细信息,请参阅http://mathiasbynens.be/notes/javascript-identifiers#valid-identifier-names

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM