ile ilgili bir sorun yaşıyorum Youtube API'sı ve node.js ile oynamaktayım. Şimdiye kadar API ve console.log
terminalinden yanıt aldım. . Bu benim senaryomnode js - JSON.parse()
Got response: 200
undefined:1
http://www.w3.or
^
SyntaxError: Unexpected token u
at Object.parse (native)
at IncomingMessage.<anonymous> (/home/ubuntu/node_temp4/index.js:19:10)
at IncomingMessage.emit (events.js:88:20)
at HTTPParser.onMessageComplete (http.js:137:23)
at Socket.ondata (http.js:1137:24)
at TCP.onread (net.js:354:27)
: Ben yanıt almak ve JSON.parse
kullanmaya çalıştığınızda
, garip hata alıyorum
var http = require("http");
var searchQuery = "cats";
var queryResponse;
var options = {
host: 'gdata.youtube.com',
path: "/feeds/api/videos?q=" + searchQuery + "&max-results=1&v=2&alt=json"
};
http.get(options, function(response) {
console.log("Got response: " + response.statusCode);
response.on('data', function(chunk){
queryResponse += chunk;
});
response.on('end', function(){
JSON.parse(queryResponse);
console.log('end');
});
}).end();
bunu ayrıştırmak denemeden önce queryResponse değeri nedir olarak
queryResponse
başlatmasını tarafından tamir edebiliriz? – Dogbert, bunu kaydederseniz terminalde [this] (http://gdata.youtube.com/feeds/api/videos?q=cats&max-results=1&v=2&alt=json) yazdırır. DÜZENLEME: daha okunabilir bir sürüm - http://gdata.youtube.com/feeds/api/videos?q=cats&max-results=1&v=2&alt=json&prettyprint=true – user1215653