0

我对我在 JSON 中看到的问题感到困惑。我正在使用我的控制器将一些值(从我的公用文件夹中的文件中读取)注入到 fxn 调用中。

应用程序/视图/比较/graphs.html.haml

  - tmp = File.readlines(txt)
  :javascript
    generate_plot(#{tmp.first})

它在我的 html 中生成:

<script>
  //<![CDATA[
    generate_plot([[[22.0,307.0,491.0,35.0,580.0,40.0,387.0,28.0,34.0,519.0,4.0,59.0,33.0,448.0,24.0,341.0],["2011-04-27T05:32:00-06:00","2011-04-27T05:32:00-06:00","2011-05-20T02:49:00-06:00","2011-05-20T02:49:00-06:00","2010-10-12T23:27:00-06:00","2010-10-12T23:27:00-06:00","2010-11-21T19:20:00-07:00","2010-11-21T19:20:00-07:00","2011-11-03T08:59:00-06:00","2011-11-03T08:59:00-06:00","2011-02-22T03:24:00-07:00","2011-02-22T03:24:00-07:00","2010-08-17T20:26:00-06:00","2010-08-17T20:26:00-06:00","2011-11-09T06:15:00-07:00","2011-11-09T06:15:00-07:00"]],[[24.0,463.0,566.0,31.0,864.0,57.0,28.0,596.0,717.0,47.0,31.0,28.0,596.0,35.0,597.0,622.0,463.0,24.0,463.0,24.0,719.0,51.0,556.0,30.0,51.0,891.0,30.0,556.0,494.0,38.0,23.0,443.0,581.0,28.0,581.0,28.0,556.0,30.0,622.0,31.0],["2010-10-15T10:04:00-06:00","2010-10-15T10:04:00-06:00","2010-09-20T04:24:00-06:00","2010-09-20T04:24:00-06:00","2010-01-08T02:10:00-07:00","2010-01-08T02:10:00-07:00","2010-09-02T20:40:00-06:00","2010-09-02T20:40:00-06:00","2010-07-08T13:11:00-06:00","2010-07-08T13:11:00-06:00","2010-02-22T23:10:00-07:00","2010-09-15T04:13:00-06:00","2010-09-15T04:13:00-06:00","2010-05-08T19:01:00-06:00","2010-05-08T19:01:00-06:00","2010-02-22T23:10:00-07:00","2010-01-10T18:59:00-07:00","2010-01-10T18:59:00-07:00","2010-06-23T14:10:00-06:00","2010-06-23T14:10:00-06:00","2010-04-04T21:57:00-06:00","2010-04-04T21:57:00-06:00","2010-01-09T11:01:00-07:00","2010-01-09T11:01:00-07:00","2010-04-30T02:10:00-06:00","2010-04-30T02:10:00-06:00","2010-10-08T13:59:00-06:00","2010-10-08T13:59:00-06:00","2010-03-03T13:12:00-07:00","2010-03-03T13:12:00-07:00","2010-06-29T15:06:00-06:00","2010-06-29T15:06:00-06:00","2010-02-14T05:47:00-07:00","2010-02-14T05:47:00-07:00","2010-06-18T05:23:00-06:00","2010-06-18T05:23:00-06:00","2010-05-12T20:05:00-06:00","2010-05-12T20:05:00-06:00","2010-03-04T19:18:00-07:00","2010-03-04T19:18:00-07:00"]],2])
  //]]>
</script>

我检查并重新检查了我的输入,但我收到此错误:

意外的令牌错误,

当我简单地删除括号和函数调用时,我的 Json 是有效的:

http://jsfiddle.net/VVL8C/

我不确定还有什么问题。

谢谢

4

1 回答 1

0

这是一个有效的 JSON 示例

var myJSONObject = {"bindings": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ]
};

http://www.json.org/js.html

最后而不是,2]) 尝试

,[[2],[""]] )
于 2012-07-16T22:17:13.603 回答