Reputation: 33
I have the following JSON Data:
{
"city": {
"city_code":"DE0001516",
"post":"28195",
"forecast": {
"2012-09-10": {
"p":"24",
"w":"10",
"06:00": {
"p":"5",
"w":"20",
"tn":"15",
"tx":"21",
"w_txt":"wolkig"
}
}
}
}
}
Normally I read the data through this function:
function(data){ $("#").html(data.city.post); }
How do I get the data from 06:00?
function(data){ $("#").html( data.city.forecast.2012-09-10.06:00.w); }
doesn’t work. I think this has something to do with time and date format.
Upvotes: 3
Views: 219
Reputation: 7315
Try with :
data.city.forecast['2012-09-10']['06:00'].w
Another problem is $("#")
. The selector seems to be wrong. Which element are you targeting ?
Upvotes: 1
Reputation: 46647
You can't read property names with those special characters in them. They need to be quoted:
data.city.forecast["2012-09-10"]["06:00"].w
Here's a related question:
any string can be a property name ... some properties can only be accessed using the bracket syntax.
Upvotes: 2
Reputation: 22817
Use bracket notation:
data.city.forecast['2012-09-10']['06:00']
Upvotes: 1