Note that there are some explanatory texts on larger screens.

plurals
  1. POnodejs - parsing chunked twitter json
    text
    copied!<p>The nodejs server 'gets' this JSON stream from Twitter and sends it to the client:</p> <pre><code>stream.twitter.com/1/statuses/filter.json?track=gadget </code></pre> <p>The data returned to the client is 'chunked' JSON and both JSON.parse(chunk) and eval('(' + chunk + ')') on the client side result in parsing errors. Concatenating the chucked pieces and waiting for the 'end' event isn't a solution either</p> <p>I noticed previous samples used something like this on the client side that apparently worked before:</p> <pre><code> socket.onmessage = function(chunk) { data = eval("(" + chunk.data + ")"); alert(data.user.screen_name); </code></pre> <p>I'm using this on the client side and it results in a parsing error:</p> <pre><code>var socket = new io.Socket(); socket.on('message', function(chunk) { var data = eval('(' + chunk + ')'); // parsing error alert(data.screen_name): </code></pre> <p>I know that its successfully returning a JSON chunk with:</p> <pre><code> var socket = new io.Socket(); socket.on('message', function(chunk) { alert(chunk): // shows a JSON chunk </code></pre> <p>Server:</p> <pre><code> response.on('data', function (chunk) { client.each(function(e) { e.send(chunk); }); </code></pre> <p>Did something change or what else em I doing wrong?</p> <p><strong>UPDATE:</strong> The 'end' event does not fire because its streaming?</p> <pre><code>http.get({ headers: { 'content-type': 'application/json' }, host: 'stream.twitter.com', path: '/1/statuses/filter.json?track... }, function(res) { res.setEncoding('utf8'); res.on('data', function (chunk) { client.each(function(e) { e.send(chunk); }); }); // does not fire res.on('end', function () { }); ... </code></pre> <p>I'm looking into the difference with http 1.0 and http 1.1 as far as sending chunked data.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload