D3.js和Drupal - SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符

时间:2014-05-16 21:48:44

标签: javascript json d3.js drupal-7

这很奇怪......我使用Drupal和一个输出JSON文件的Drupal视图。如果我直接从嵌入式javascript访问该文件,我会收到错误:SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符 但是,如果我通过Drupal视图复制文件输出它传递JSON验证并且如果我将生成的文件粘贴到javascript中则没有错误并且脚本正确执行。 这是生成的JSON数据:

{"nodes":[{"node":{"body":"This is a very short story","category":"Heatwave","latitude":43.6689985,"longitude":-79.3155716,"link":"http://crewtoronto.ca/entityform/1"}},{"node":{"body":"This is a short description of the effect of the ice storm on our household","category":"Ice storm","latitude":43.6689985,"longitude":-79.3155716,"link":"http://crewtoronto.ca/entityform/2"}},{"node":{"body":"The ice storm affected the large tree in our backyard. Several large limbs broke off covering a third of the yard. We have slowly cleaned it up, managing to do so ourselves to save some money. We also did not have any power for two days. We lost a bit of food.","category":"Ice storm","latitude":43.6920105,"longitude":-79.3027845,"link":"http://crewtoronto.ca/entityform/6"}}]} 

知道可能出现什么问题吗?

1 个答案:

答案 0 :(得分:0)

我发现了导致问题的原因。如果有人遇到同样的问题,那就是Drupal视图中的Views API设置。以下是有关设置的内容:"不使用View API模式意味着JSON直接输出,服务器停止正常的页面处理。使用它意味着服务器在输出JSON后不会停止处理。这允许Views API与视图一起使用,而不必过早终止页面处理。"我一直在使用Views API。