JSON API : does not work when there is a field starting with a number

63 Views Asked by At

Here is one field of the JSON API from accuweather : data.list[i].rain.3h It doesn't work when using Javascript (from cloudpebble). This line produces an error : var rain =1; rain = data.list[i].rain.3h; The error is : [PHONE] pebble-app.js:?: SyntaxError: Unexpected token ILLEGAL [PHONE] pebble-app.js:?: JS failed.

The problem comes from the "3" because it works for all others field. Do you know a workaround to make it work ?

PS : API description is here (not sure you need it): http://openweathermap.org/forecast5

1

There are 1 best solutions below

0
nj2000 On

Somebody gave me the solution : I can use this syntax to make it work when it starts with a digit : rain=data.list[i].rain['3h']