Problem with json.decode

This has been driving me nuts, so thought I’d go ahead and post to see if anyone else has an idea on it! I’m trying to get weather information from wunderground.com and return/decode it with json (which according to their documentation is the preferred method.

[lua]network.request( “http://api.wunderground.com/api/87198b0e4ee22896/conditions/q/30.54,-97.73.json”, “GET”, networkListener )[/lua]

Then, within my networkListener function, I call:

[lua]local response = json.decode(event.response)
response = json.decode(response)[/lua]

However, when I do this using the above URL, I get:

Runtime error
Invalid input: ’
{

…[the full expected response]…

stack traceback:
[C]: ?
[C]: in function ‘?’
?: in function ‘Read’
?: in function <?:434>
(tail call): ?
?: in function <?:434>
(tail call): ?
?: in function <?:434>
(tail call): ?
(tail call): ?

Any ideas whats going on here?
[import]uid: 64538 topic_id: 19466 reply_id: 319466[/import]

gbailey - Will need to see the json string to help you. But it seems like your json string is malformed… [import]uid: 84539 topic_id: 19466 reply_id: 75118[/import]

Thanks Bejoy, I’m including it below. That’s what I was thinking too, however if I use the url in Firefox or in a json reader (ie: Jason on my Mac), it comes back ok (ie: is readable).

[blockcode]
Runtime error
Invalid input: ’
{
“response”: {
“version”: “0.1”
,“termsofService”: “http://www.wunderground.com/weather/api/d/terms.html
,“features”: {
“conditions”: 1
}
}
, “current_observation”: {
“image”: {
“url”:“http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png”,
“title”:“Weather Underground”,
“link”:“http://www.wunderground.com
},
“display_location”: {
“full”:“Round Rock, TX”,
“city”:“Round Rock”,
“state”:“TX”,
“state_name”:“Texas”,
“country”:“US”,
“country_iso3166”:“US”,
“zip”:“78681”,
“latitude”:“30.540000”,
“longitude”:"-97.730000",
“elevation”:“245.00000000”
},
“observation_location”: {
“full”:“Brushy Creek North Hjornevik’s, Round Rock, Texas”,
“city”:“Brushy Creek North Hjornevik’s, Round Rock”,
“state”:“Texas”,
“country”:“US”,
“country_iso3166”:“US”,
“latitude”:“30.541536”,
“longitude”:"-97.735313",
“elevation”:“708 ft”
},
“estimated”: {
},
“station_id”:“KTXROUND25”,
“observation_time”:“Last Updated on December 21, 9:12 AM CST”,
“observation_time_rfc822”:“Wed, 21 Dec 2011 09:12:47 -0600”,
“observation_epoch”:“1324480367”,
“local_time_rfc822”:“Wed, 21 Dec 2011 09:12:50 -0600”,
“local_epoch”:“1324480370”,
“local_tz_short”:“CST”,
“local_tz_long”:“America/Chicago”,
“weather”:“Clear”,
“temperature_string”:“43.9 F (6.6 C)”,
“temp_f”:43.9,
“temp_c”:6.6,
“relative_humidity”:“55%”,
“wind_string”:“Calm”,
“wind_dir”:“WNW”,
“wind_degrees”:289,
“wind_mph”:0.0,
“wind_gust_mph”:0,
“pressure_mb”:“1018.2”,
“pressure_in”:“30.07”,
“pressure_trend”:“0”,
“dewpoint_string”:“29 F (-2 C)”,
“dewpoint_f”:29,
“dewpoint_c”:-2,
“heat_index_string”:“NA”,
“heat_index_f”:“NA”,
“heat_index_c”:“NA”,
“windchill_string”:“44 F (7 C)”,
“windchill_f”:“44”,
“windchill_c”:“7”,
“visibility_mi”:“10.0”,
“visibility_km”:“16.1”,
“solarradiation”:"",
“UV”:“1”,
“precip_1hr_string”:“0.00 in ( 0 mm)”,
“precip_1hr_in”:“0.00”,
“precip_1hr_metric”:" 0",
“precip_today_string”:“0.00 in (0 mm)”,
“precip_today_in”:“0.00”,
“precip_today_metric”:“0”,
“icon”:“clear”,
“icon_url”:“http://icons-ak.wxug.com/i/c/k/clear.gif”,
“forecast_url”:“http://www.wunderground.com/US/TX/Round_Rock.html”,
“history_url”:“http://www.wunderground.com/history/airport/KTXROUND25/2011/12/21/DailyHistory.html”,
“ob_url”:“http://www.wunderground.com/cgi-bin/findweather/getForecast?query=30.541536,-97.735313
}
}

stack traceback:
[C]: ?
[C]: in function ‘?’
?: in function ‘Read’
?: in function <?:434>
(tail call): ?
?: in function <?:434>
(tail call): ?
?: in function <?:434>
(tail call): ?
(tail call): ?
[/blockcode] [import]uid: 64538 topic_id: 19466 reply_id: 75119[/import]

Hi, gbailey!

Have you solved this problem? I want to use wunderground json too and have the same runtime error on a free trial 2011.704 version. [import]uid: 117007 topic_id: 19466 reply_id: 86591[/import]

Yes, there was a bug in the json.decode which prevented this from working due to how it handled NULLs. It’s fixed in the latest build I believe, but not sure about the trial version. [import]uid: 64538 topic_id: 19466 reply_id: 86619[/import]

Thanks! I heard about this bug fix, just want to know if there no more problems with parsing wunderground json file.
[import]uid: 117007 topic_id: 19466 reply_id: 86623[/import]

Yeah, no problem. I’m glad you asked as I (or someone at Ansca) should have posted the “answer”. [import]uid: 64538 topic_id: 19466 reply_id: 86633[/import]