I have another simple question about Node. I'm trying to make a simple http request to the Open Courseware search API (http://www.ocwsearch.com/api), but I'm running into some problems actually parsing the JSON... which normally hasn't been a problem. The request returns a string that has escaped characters and slashes, and so I've run a replace and an unescape on the response string, but this ends up returning something like '[object Object]'. Right now, all I really want to do is be able to SEE what's finally being returned, so I can tell whether or not I can finally parse it as valid JSON. Unfortunately, this is not working either. I've read a couple of similar threads on stack overflow, but I'm still unable to get it to work.
What I've tried:
- iterating over the object being passed, because I thought it'd be something with key value pairs, and running over it, logging it each time. However, this prints it out as a string:
[
o
b
... all the way to the end (])
Given x as the returned formatted object in question,
- using "" + x, toString(), to try to convert it to a string
- using console.log("%j", x) as per How do you log content of a JSON object in Node.js?
None of these seem to work though, they're all returning me [object Object].
I've even tried it in jsfiddle: http://jsfiddle.net/S47QL/2/ I'm replacing console.log with alert, and it seems to be re
My code:
var request = require('request');$
request('http://www.ocwsearch.com/api/v1/search.json?q=' + skill + '&contact=http%3a%2f%2fwww.ocwsearch.com%2fabout/',$
function(error, response, body){$
if(!error && response.statusCode == 200){~$
console.log(response.toString().replace(/\\\//g, "/"));$
var x = response.toString().replace(/\\\//g, "/");$
console.log(x)$
console.log(x.keys());$
}$
});$