当前位置: 代码迷 >> JavaScript >> 未捕获的语法错误:意外的令牌-云代码解析保存功能
  详细解决方案

未捕获的语法错误:意外的令牌-云代码解析保存功能

热度:49   发布时间:2023-06-13 11:31:58.0

情况-遍历事件数组并从已解析的JSON分配属性

预期结果-上传到Parse云存储

我正在使用的API-

我是Java的新手(实际上可能有多个语法错误)

我不知道为什么在尝试部署到Parse Cloud Code时在第83行此

我传递的是-

var cities = ["San Francisco", "London"];
eventsArray = JSON.parse(httpResponse.text)["events"];

loopEvents(eventsArray);

整个功能为屏幕截图(突出显示语法以提高可读性)->

作为文本的功能->

function loopEvents(events) {
   if  (j == cities.length) {j=0};

   for (var i = 0; i < events.length; i++) {

      //Parse.Cloud.useMasterKey(); is not needed ATM I think
      console.log("assigning properties for " + cities[j] + ".");

      list.save({ // saving properties
         number: String(i); //               ****THIS IS THE LINE 83****
         uri: events[i]["resource_uri"];
         url: events[i]["url"];
         id: events[i]["id"];
         name: events[i]["name"]["text"];
         description: events[i]["description"]["text"] || "None provided.";
         status: events[i]["status"];
         capacity: String(events[i]["capacity"]);
         logo: events[i]["logo_id"]["logo"] || "http://www.ecolabelindex.com/files/ecolabel-logos-sized/no-logo-provided.png";
         start: moment(events[i]["start"]["utc"]);
         end: moment(events[i]["end"]["utc"]);
         online: events[i]["online_event"];
         currency: events[i]["currency"];
         ticketClasses: events[i]["ticket_classes"] || "It's freeee!";
         ticketClassesNames: events[i]["ticket_classes"]["name"] || "None provided.";
         ticketClassesCost: events[i]["ticket_classes"]["cost"] || "It's freeee!";
         ticketClassesDescription: events[i]["ticket_classes"]["description"] || "None provided.";
      }, {
         success: function(list) {
            console.log("RIP CloudCode, we had good times!");
         },
         error: function(list, error) {
            console.log("u fuc*ed up, with error: " + error.text + ", son.");
         }
      });
   }
   j++;
}

也许这都是错误的,感谢您的努力和建设性的回答;)))如果您需要其他任何信息,请在下面评论,然后我将进行编辑。

EDIT.1-更换后; ,我收到以下

当您使用object ,分号; 是无效的语法。

删除; 从对象内部的所有行。

number: String(i);
//               ^

使用,逗号代替。

number: String(i),
//               ^

// Notice the comma at the end of each element

list.save({ // saving properties
    number: String(i),
    uri: events[i]["resource_uri"],
    url: events[i]["url"],
    id: events[i]["id"],
    name: events[i]["name"]["text"],
    description: events[i]["description"]["text"] || "None provided.",
    status: events[i]["status"],
    capacity: String(events[i]["capacity"]),
    logo: events[i]["logo_id"]["logo"] || "http://www.ecolabelindex.com/files/ecolabel-logos-sized/no-logo-provided.png",
    start: moment(events[i]["start"]["utc"]),
    end: moment(events[i]["end"]["utc"]),
    online: events[i]["online_event"],
    currency: events[i]["currency"],
    ticketClasses: events[i]["ticket_classes"] || "It's freeee!",
    ticketClassesNames: events[i]["ticket_classes"]["name"] || "None provided.",
    ticketClassesCost: events[i]["ticket_classes"]["cost"] || "It's freeee!",
    ticketClassesDescription: events[i]["ticket_classes"]["description"] || "None provided."
}, {

请参阅

票证类实际上是一个数组,要访问它,我不得不在httpRequest中添加一个expand参数,除了代码本身很好之外,还可以通过Tushar进行语法校正。