简体   繁体   中英

D3.js and Drupal - SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

This is very strange ... I use Drupal and a Drupal view which outputs a JSON file. If I access the file directly from the embedded javascript I get the error: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data However, if I copy the file output by the Drupal view it passes JSON validation AND if I paste the file that is produced into the javascript there is no error and the script executes correctly. Here is the generated JSON data:

{"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"}}]} 

Any idea what could be wrong?

I found out what caused the problem. In case anyone has the same problem it was the Views API setting in the Drupal view. Here is what it says about the setting: "Not using View API mode means the JSON gets output directly and the server ceases normal page processing. Using it means the server does not cease processing after outputting the JSON. This allows the Views API to be used with the view without having to prematurely terminate page processing." I had being using Views API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM