【问题标题】:Syntax error, when I try initialize a key with hyphen (-) [duplicate]语法错误,当我尝试使用连字符 (-) 初始化键时 [重复]
【发布时间】:2017-06-06 23:24:15
【问题描述】:

当下面的对象初始化时,会抛出错误。

var postData ={
  file_path : "https://s3-us-west-2.amazonaws.com/ps/eams/6-48K.mxf",
  template_type : "1",
  template_name : "Basic Tests",
  job_type : "0",
  user_note : "my job",
  access-key-ID : "AKAEBQ",
  access-key-SECRET : "ZZHfO"
};

错误是

    access-key-ID : "AKAEBQ",
    ^
    SyntaxError: Unexpected token -

我该如何处理?

【问题讨论】:

    标签: javascript node.js syntax-error


    【解决方案1】:

    将键设置为字符串:

    var postData ={
      'file_path' : "https://s3-us-west-2.amazonaws.com/ps/eams/6-48K.mxf",
      'template_type' : "1",
      'template_name' : "Basic Tests",
      'job_type' : "0",
      'user_note' : "my job",
      'access-key-ID' : "AKAEBQ",
      'access-key-SECRET' : "ZZHfO"
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-19
      • 2019-07-28
      • 2019-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多