ngplayground
ngplayground

Reputation: 21617

Parsing JSON in jquery Yahoo Weather API

I cannot figure this out at all.

my current json results the following using console.log(json)

Click to view Json Response

I was wondering if someone could help me retrieve the Condition part?

EDIT

                       var geoFORECAST = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=%2726344339%27%20and%20u=%27c%27&format=json';
                    $.getJSON(geoFORECAST, function(json) {
                       console.log(json);
                       console.log(json.query.results.item.condition.text);
                     });

Upvotes: 1

Views: 2048

Answers (3)

Lemex
Lemex

Reputation: 3794

Item is already parsed so save what that pages sends back to varible test and code below iwll work

and access things like..

test.query.results.item.condition.text 

Which will return a value

To do conditions you could do

var b =  test.query.results.item.condition.text ;

if(b == ???) or even > or < or what ever is required

Upvotes: 0

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57650

Use native JSON object.

var obj = JSON.parse(json);
var condition = obj.query.results.channel.item.condition;

Upvotes: 1

Madbreaks
Madbreaks

Reputation: 19539

You need to use parseJSON: http://api.jquery.com/jQuery.parseJSON/

Then just access the Condition var like you would any object property.

Upvotes: 1

Related Questions