0

I am using ajax to retrieve JSON data from an API. One data path to a piece of data on the API is rain then 1h. So theoretically this var call should be var rainfall = data.rain.1h; However, Java does not like the the "1" number being in here, and returns an error. How do I format this data call, and specifically the "1h" part, so that java uses it as part of a data call and therefore retrieves the data associated with "1h" on the API page, given below. Thank you very much.


     // API URL A537
   var apiUrl              =   'http://api.openweathermap.org/data/2.5/weather?lat=53.2388&lon=-1.9944&appid=&units=imperial';
   
   // AJAX
   jQuery.ajax ({
       url: apiUrl,
       type: 'GET',
       dataType: 'json',
       success: function(data) {
   
           console.log(data);
   
           // Operation
           var rainfall        =   data.rain.1h;
      
       // jQuery call 
       jQuery('#retrievedrainfall')=html.( rainfall ); 

1 Answers1

0

Try using data.rain['1h']; to access the 1h property.

zeterain
  • 1,140
  • 1
  • 10
  • 15