javascript - worldweatheronline API response error -


i trying pull weather info 'worldweatheronline' using $http call in angular factory:

this.testapi = function(coords) {         var deferred = $q.defer();          $http.jsonp(api_roots + '?key=9834687w634087623eg8932te&q=' + coords.latitude + ',' + coords.longitude + '&cc=yes&includelocation=yes&format=json')         .then(function(response) {           deferred.resolve(response.current_condition);           console.log(response.current_condition);         }, function(error) {             deferred.reject(error);         }         );         return deferred.promise;     }; 

and controller:

$scope.updatelocalweather = function() {       $geolocation.get().then(         function(position) {           $weather.testapi(position.coords).then(             function(weather) {               $scope.localweather = weather;                  $ionicslideboxdelegate.update();              }           );         }       );     }; 

and console shows error:

uncaught syntaxerror: unexpected token : 

but response comes through when console.log:

{ "data": { "current_condition": [ {"cloudcover": "0", "feelslikec": "11", "feelslikef": "51", "humidity": "42", "observation_time": "07:29 am", "precipmm": "0.0", "pressure": "1029", "temp_c": "11", "temp_f": "51", "visibility": "10", "weathercode": "113",  "weatherdesc": [ {"value": "sunny" } ],  "weathericonurl": [ {"value": "http:\/\/cdn.worldweatheronline.net\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png" } ], "winddir16point": "sw", "winddirdegree": "235", "windspeedkmph": "4", "windspeedmiles": "2" } ],  "nearest_area": [ { "areaname": [ {"value": "randjesfontein" } ],  "country": [ {"value": "south africa" } ], "latitude": "-25.952", "longitude": "28.143", "population": "0",  "region": [ {"value": "gauteng" } ],  "weatherurl": [ {"value": "http:\/\/www.worldweatheronline.com\/v2\/weather.aspx?q=-25.9484274,28.1395815" } ] } ],  "request": [ {"query": "lat -25.95 , lon 28.14", "type": "latlon" } ],  "weather": [ { "astronomy": [ {"moonrise": "09:08 pm", "moonset": "08:47 am", "sunrise": "06:45 am", "sunset": "05:43 pm" } ], "date": "2015-08-03",  "hourly": [ {"chanceoffog": "0", "chanceoffrost": "0", "chanceofhightemp": "0", "chanceofovercast": "0", "chanceofrain": "0", "chanceofremdry": "0", "chanceofsnow": "0", "chanceofsunshine": "100", "chanceofthunder": "0", "chanceofwindy": "0", "cloudcover": "0", "dewpointc": "-3", "dewpointf": "26", "feelslikec": "9", "feelslikef": "48", "heatindexc": "9", "heatindexf": "47", "humidity": "43", "precipmm": "0.0", "pressure": "1028", "tempc": "9", "tempf": "47", "time": "200", "visibility": "10", "weathercode": "113",  "weatherdesc": [ {"value": "clear" } ]} 

really unsure have done wrong here. appreciated.

you can parse json better results:

$scope.localweather = json.parse(weather); 

but checked json output json lint , sais json wrong. check in developer console if same json comes weather service outputted? if yes, problem api, cannot anything.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -