我在node.js
中有以下代码console.log("Sending request "+sys.inspect(request));
var request=Yapi.request('get',config.path+'/index.php?
command='+request.command+'&'+querystring.stringify(request),config);
request.end();
var body=''
request.on('response',function(response) {
response.on('data',function(chunk) {body += chunk;});
response.on('end',function() {
var rdata=JSON.parse(body);
if (typeof(rdata) != 'object') {
return proceed(false,{errno:'002',message:'Cannot parse yapi
response ('+response.responseCode+')'});
}
proceed(true,rdata);
});
});
发出此错误
Logging in { sessionId: '9165703144390136',
command: 'login',
username: 'rahul',
password: '12345' }
sessionId=9165703144390136&command=login&username=rahul&password=12345
Sending request { sessionId: '9165703144390136',
command: 'login',
username: 'rahul',
password: '12345' }
undefined:5
d":"1","id_session":"ecvgvc36d17qran917pml3t681","systemgibid":"54"}
<script la
^^
SyntaxError: Unexpected token ILLEGAL
at Object.parse (native)
at IncomingMessage.<anonymous> (/home/ubuntu/nodes/youngib/lib/
yapi.js:103:19)
at IncomingMessage.emit (events.js:41:20)
at HTTPParser.onMessageComplete (http.js:112:23)
at Client.onData [as ondata] (http.js:889:27)
at Client._onReadable (net.js:762:27)
at IOWatcher.onReadable [as callback] (net.js:276:10)
at node.js:616:9
请说明问题所在。
答案 0 :(得分:0)
非法令牌意味着JavaScript属性正在使用不应该使用的字符,例如:
my-var = 1;
答案 1 :(得分:0)
你在变量值的中间有换行符,你会错过一些分号。 请尝试使用此类代码:
console.log("Sending request "+sys.inspect(request));
var request = Yapi.request('get', config.path + '/index.php?command=' + request.command + '&' + querystring.stringify(request), config);
request.end();
var body='';
request.on('response', function(response) {
response.on('data', function(chunk) { body += chunk; });
response.on('end',function() {
var rdata = JSON.parse(body);
if (typeof(rdata) != 'object') {
return proceed(false, { errno:'002', message: 'Cannot parse yapi response (' + response.responseCode + ')' });
}
proceed(true,rdata);
});
);
答案 2 :(得分:0)
在api调用中有问题,它是returnig脚本标记
undefined:5
d":"1","id_session":"ecvgvc36d17qran917pml3t681","systemgibid":"54"}
<script la