我正在测试将Apache Stanbol与node.js结合使用的代码示例。但是,这些代码对我不起作用。例如代码
var request = require('request');
var fs = require('fs');
fs.createReadStream('testdata.txt').pipe(request.post(
{
url:'http://localhost:8080/enhancer',
headers:{accept:'application/json'}
},
function(error, response, body) {
if (!error && response.statusCode == 200) {
enhancements = JSON.parse(body)['@graph']
for (var i = 0; i < enhancements.length; i++) {
if (enhancements[i]['enhancer:entity-reference']) {
console.log(enhancements[i]['enhancer:entity-reference'])
}
}
} else {
console.log('Got status code: '+response.statusCode)
}
}))
返回以下错误
C:\Users\lily\ex>node simple-client.js
C:\Users\lily\ex\simple-client.js:11
for (var i = 0; i < enhancements.length; i++) {
^
TypeError: Cannot read property 'length' of undefined
at Request.callback (C:\Users\lily\ex\simple-client.js:11:42)
at Request.<anonymous> (C:\Users\lily\ex\node_modules\request\main.js:290:21)
at Request.emit (events.js:180:13)
at IncomingMessage.<anonymous> (C:\Users\lily\ex\node_modules\request\main.js:278:54)
at IncomingMessage.emit (events.js:185:15)
at endReadableNT (_stream_readable.js:1106:12)
at process._tickCallback (internal/process/next_tick.js:178:19)
很抱歉,我是使用Stanbol和Node.js的新手。