Javascript 意外标记';使用节点导出服务器生成png图表时
我正在尝试使用节点导出服务器库导出highchart图形Javascript 意外标记';使用节点导出服务器生成png图表时,javascript,json,node.js,highcharts,cmd,Javascript,Json,Node.js,Highcharts,Cmd,我正在尝试使用节点导出服务器库导出highchart图形 npm安装海图导出服务器-g 库和教程: 与Github的文档一样,我使用highcharts导出服务器--enableServer1启动服务器,并使用另一个cmd窗口尝试运行以下命令: curl -H "Content-Type: application/json" -X POST -d '{"infile":{"title": "text": "Steep Chart"}, "xAxis": {"categories": ["Jan
npm安装海图导出服务器-g
库和教程:
与Github的文档一样,我使用highcharts导出服务器--enableServer1
启动服务器,并使用另一个cmd窗口尝试运行以下命令:
curl -H "Content-Type: application/json" -X POST -d '{"infile":{"title": "text": "Steep Chart"}, "xAxis": {"categories": ["Jan", "Feb", "Mar"]}, series": [{"data": [29.9, 71.5, 106.4]}]}}' 127.0.0.1:7801 -o mychart.png
运行此命令会导致意外令牌”
或'代码>。此错误会在执行命令的终端弹出。将“
更改为”
或将更改为“
或将更改为”,在这方面会有所帮助。不会弹出错误,并且该命令似乎有效:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1273 100 1137 100 136 71062 8500 --:--:-- --:--:-- --:--:-- 71062
已生成名为mychart.png
的图像,但无法打开
在服务器端,出现以下错误:
SyntaxError: Unexpected token ' in JSON at position 1
at JSON.parse (<anonymous>)
at parse (C:\Users\Maarten Courtin\AppData\Roaming\npm\node_modules\highcharts-export-server\node_modules\body-parser\lib\types\json.js:88:17)
at C:\Users\Maarten Courtin\AppData\Roaming\npm\node_modules\highcharts-export-server\node_modules\body-parser\lib\read.js:116:18
at invokeCallback (C:\Users\Maarten Courtin\AppData\Roaming\npm\node_modules\highcharts-export-server\node_modules\raw-body\index.js:262:16)
at done (C:\Users\Maarten Courtin\AppData\Roaming\npm\node_modules\highcharts-export-server\node_modules\raw-body\index.js:251:7)
at IncomingMessage.onEnd (C:\Users\Maarten Courtin\AppData\Roaming\npm\node_modules\highcharts-export-server\node_modules\raw-body\index.js:307:7)
at emitNone (events.js:106:13)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1056:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
SyntaxError:JSON中位置1处的意外标记
在JSON.parse()处
解析时(C:\Users\marten Courtin\AppData\Roaming\npm\node\u modules\highcharts export server\node\u modules\body parser\lib\types\json.js:88:17)
在C:\Users\Maarten Courtin\AppData\Roaming\npm\node\u modules\highcharts export server\node\u modules\body parser\lib\read.js:116:18
在invokeCallback(C:\Users\Maarten Courtin\AppData\Roaming\npm\node\u modules\highcharts export server\node\u modules\raw body\index.js:262:16)
完成时(C:\Users\Maarten Courtin\AppData\Roaming\npm\node\u modules\highcharts export server\node\u modules\raw body\index.js:251:7)
在IncomingMessage.onEnd(C:\Users\Maarten Courtin\AppData\Roaming\npm\node\u modules\highcharts export server\node\u modules\raw body\index.js:307:7)
在emitNone(events.js:106:13)
在IncomingMessage.emit(events.js:208:7)
在endReadableNT(_stream_readable.js:1056:12)
at _combinedTickCallback(内部/流程/下一步_tick.js:138:11)
有人知道这个问题的解决方案吗?问题出在Windows命令提示符下。Unix shell和Windows命令提示符对引号的处理方式不同。您使用的命令在Unix上有效,但在Windows上无效
要解决这个问题,必须使用带转义字符的双引号,如下所示
curl -H "Content-Type: application/json" -X POST -d "{\"infile\":{\"title\": {\"text\": \"Steep Chart\"}, \"xAxis\": {\"categories\": [\"Jan\", \"Feb\", \"Mar\"]}, \"series\": [{\"data\": [29.9, 71.5, 106.4]}]}}" 127.0.0.1:7801 -o mychart.png
我还没有测试过上面的命令,这里和那里可能缺少一些引用,但我想你已经明白了
无效的JSON:请注意,您发布的JSON无效。请检查它。命令是多行的吗?如果是,您需要在每行末尾加上反斜杠(\)。不是。我只是在多行中提到了它,为了清楚起见,但这可能不起作用。问得好。