javascript - How do I access a certain string variable in a json API? -
i using weatherunderground api, , access forecast today. use parsed_json[][] until variable need, in case there array. here code:
function findweather() { jquery(document).ready(function($) { $.ajax({ url : "http://api.wunderground.com/api/c531e176f43b999d/forecast/q/ct/old_greenwich.json", datatype : "jsonp", success : function(parsed_json) { var forecasts = parsed_json['forecast']['txt_forecast']['forecastday: 0']['fcttext']; var forecaststring = "the weather is" + forecasts + "." speak(" test" + forecaststring); } }); }); } function speak(x) { var msg = new speechsynthesisutterance(x); window.speechsynthesis.speak(msg); }
if go url, see entire sheet , info trying access. i've been trying solve few hours, , can't find google.
try this:
parsed_json['forecast']['txt_forecast']['forecastday'][0]['fcttext'];
don't know expect :0 do, won't de-reference array.
Comments
Post a Comment