我想在Rullete上创建一个基本的网站。我有代码和脚本。当我运行脚本时,我得到了这个错误。
[SyntaxError: Unexpected token <]
SyntaxError: Unexpected token <
at Object.parse (native)
at Request._callback (/var/www/html/Bot/BOT/site.js:63:16)
at Request.self.callback (/root/node_modules/request/request.js:200:22)
at emitTwo (events.js:100:13)
at Request.emit (events.js:185:7)
at Request.<anonymous> (/root/node_modules/request/request.js:1067:10)
at emitOne (events.js:95:20)
at Request.emit (events.js:182:7)
at IncomingMessage.<anonymous> (/root/node_modules/request/request.js:988:12)
at emitNone (events.js:85:20)
我不知道如何解决这个问题。有人能帮助我吗?
Site.js
第59-107行
load();
var prices;
request('http://backpack.tf/api/IGetMarketPrices/v1/?key=56fce4a5c4404545131c8fcf&compress=1&appid=730', function(error, response, body) {
prices = JSON.parse(body);
if(prices.response.success == 0) {
logger.warn('Loaded fresh prices');
if(fs.existsSync(__dirname + '/prices.txt')){
prices = JSON.parse(fs.readFileSync(__dirname + '/prices.txt'));
logger.warn('Prices loaded from cache');
} else {
logger.error('No prices in cache');
process.exit(0);
}
} else {
fs.writeFileSync('prices.txt', body);
logger.trace('New prices loaded');
}
});
updateHash();
function updateHash() {
query('SELECT * FROM `hash` ORDER BY `id` DESC LIMIT 1', function(err, row) {
if(err) {
logger.error('Cant get the hash, stopping');
logger.debug(err);
process.exit(0);
return;
}
if(row.length == 0) {
logger.error('Wrong hash found, stopping');
process.exit(0);
} else {
if(hash != row[0].hash) logger.warn('Loaded hash'+row[0].hash);
hash = row[0].hash;
}
});
}
io.on('connection', function(socket) {
var user = false;
socket.on('hash', function(hash) {
query('SELECT * FROM `users` WHERE `hash` = '+pool.escape(hash), function(err, row) {
if((err) || (!row.length)) return socket.disconnect();
user = row[0];
users[user.steamid] = {
socket: socket.id,
balance: parseInt(row[0].balance)
}
第63行是
prices = JSON.parse(body);
完整档案在这里http://pastebin.com/yRELaZku
答案 0 :(得分:0)
看起来请求的主体是不可解析的json。做一个
console.log(body)
检查
中传递的数据答案 1 :(得分:0)
最后,您应该将Prices
更改为list
或Prices
更改为dictionary
:
prices = [];
或
prices = {};