से JSON का अनुरोध करने के साथ एन्कोडिंग समस्या मैं इसे अपने जीवन के लिए नहीं समझ सकता। नीचे request मॉड्यूल के साथ एक कार्यान्वयन है, लेकिन मैंने node-XMLHttpRequest मॉड्यूल के साथ कोई फायदा नहीं हुआ है।स्टैक ओवरव्लो एपीआई
var request = require('request');
var url = 'http://api.stackexchange.com/2.1/questions?pagesize=100&fromdate=1356998400&todate=1359676800&order=desc&min=0&sort=votes&tagged=javascript&site=stackoverflow';
request.get({ url: url }, function(error, response, body) {
if (error || response.statusCode !== 200) {
console.log('There was a problem with the request');
return;
}
console.log(body); // outputs gibberish characters like �
console.log(body.toString()); // also outputs gibberish
});
कोई एन्कोडिंग मुद्दा लगता है, लेकिन मैं ब्राउज़र में ठीक उसी कोड का उपयोग किया है (देशी एक्सएचआर वस्तुओं के साथ) है और यह समस्याओं के बिना काम करता है। मैं क्या गलत कर रहा हूं?
हां, यह समझ में आता है। धन्यवाद! –