JSON.parse错误785意外的令牌错误

时间:2019-04-26 04:46:55

标签: json ruby

我正在尝试使用JSON.parse解析Rails 5应用程序中的JSON数据。我不断收到此错误:

"#<JSON::ParserError: 785: unexpected token at ': Hours,\n  \"config\": {\n    \"blocks\": <\n      {\n        \"type\": table,\n        \"name\": Hours from Users,\n        \"fields\": [\n          \"customer\",\n          \"project\",\n          \"user\",\n          \"task\",\n          \"hour_type\",\n          \"amount\"\n        ]\n      }\n    >\n  }>"

2 个答案:

答案 0 :(得分:2)

打印消息后的外观如下:

#<JSON::ParserError: 785: unexpected token at ': Hours,
  "config": {
    "blocks": <
      {
        "type": table,
        "name": Hours from Users,
        "fields": [
          "customer",
          "project",
          "user",
          "task",
          "hour_type",
          "amount"
        ]
      }
    >
  }>

您忘了引用某些值,例如tableHours from Users,它们需要双引号"才是有效的json。

(也不确定多余的<>,可能是由于解析器错误所致)

答案 1 :(得分:1)

:json更改为:hybrid,例如:

Rails.application.config.action_dispatch.cookies_serializer = :hybrid

in this Rails issue所述: