Sunday, 8 September 2013

can not access JSON object using dot notation

can not access JSON object using dot notation

node v0.10.18 webstorm 6.0.1
I am trying to get the temperature from weather underground. I get the
object using their API and i'm trying to access the actual temperature
using:
<pre>
<code>
request(url+state+"/"+city+format, function (error, response, body) {
if (!error && response.statusCode == 200) {
var objBody = JSON.parse(body);
return objBody.current_observation.temp_f;
}
else if (error) {
console.log('error: ' + err);
}
});
</code>
</pre>
I am getting an error of "unresolved variable" for
objBody.current_observation.temp_f
I also tried using body.current_observation.temp_f directly and get the
same error. I also tried to stringify it and get the same error.
any ideas?

No comments:

Post a Comment