I just received a JSON Object from an HTTP request
[
{
"location": {
"name": "Seattle, WA",
"lat": "47.604",
"long": "-122.329",
"timezone": "-7",
"alert": "",
"degreetype": "F",
"imagerelativeurl": "http:\/\/blob.weather.microsoft.com\/static\/weather4\/en-us\/"
},
"current": {
"temperature": "81",
"skycode": "32",
"skytext": "Sunny",
"date": "2015-08-09",
"observationtime": "18:00:00",
"observationpoint": "Seattle, WA",
"feelslike": "81",
"humidity": "39",
"winddisplay": "3 mph Northwest",
"day": "Sunday",
"shortday": "Sun",
"windspeed": "3 mph",
"imageUrl": "http:\/\/blob.weather.microsoft.com\/static\/weather4\/en-us\/law\/32.gif"
},
"forecast": [
{
"low": "60",
"high": "81",
"skycodeday": "29",
"skytextday": "Partly Cloudy",
"date": "2015-08-08",
"day": "Saturday",
"shortday": "Sat",
"precip": ""
},
{
"low": "65",
"high": "82",
"skycodeday": "34",
"skytextday": "Mostly Sunny",
"date": "2015-08-09",
"day": "Sunday",
"shortday": "Sun",
"precip": "0"
},
{
"low": "66",
"high": "82",
"skycodeday": "32",
"skytextday": "Sunny",
"date": "2015-08-10",
"day": "Monday",
"shortday": "Mon",
"precip": "0"
},
{
"low": "68",
"high": "83",
"skycodeday": "30",
"skytextday": "Partly Sunny",
"date": "2015-08-11",
"day": "Tuesday",
"shortday": "Tue",
"precip": "0"
},
{
"low": "65",
"high": "88",
"skycodeday": "32",
"skytextday": "Sunny",
"date": "2015-08-12",
"day": "Wednesday",
"shortday": "Wed",
"precip": "0"
}
]
}
]
Here's the current code I have to process it:
var responseObject = JSON.parse(xhr.responseText);
var newContent = '';
for (var i = 0; i < xhr.responseText.length; i++) {
newContent += '<div class = "location">';
//newContent += '<p><b>' + xhr.responseText[i].location.pid + '</b><br>';
newContent += '<p> Name: <b>' + responseObject.location[i].location + '</b><br>';
newContent += '<p> Lat: <b>' + responseObject.location[i].lat + '</b><br>';
newContent += '<p> Long: <b>' + responseObject.location[i].long
+ '</b> <br>';
newContent += '<p> TimeZone: <b>' + responseObject.location[i].timezone +
'</b><br>';
newContent += '<p> Alert: <b>' + responseObject.location[i].alert + '</b><br>';
newContent += '<p> DegreeType: <b>' + responseObject.location[i].degreeType + '</b><br>';
newContent += '</div>';
}
The issue I am facing is that there are three different objects within one JSON object. How can I traverse through it? I'm quite new to parsing JSON data.