Hallo zusammen,
ich bräuchte eure Hilfe bei dem json Response.
Ich möchte über die API von Weather Underground Daten zum Sonnenaufgang und Sonnenuntergang ziehen.
Der http:request funktioniert soweit.
Jetzt stehe ich vor dem Problem, dass ich die Daten aus dem response explizit abgreifen will um diese dann GV zu speichern.
Ich habe es schon mit folgenden Zeilen versucht aber leider erhalte ich immer eine Fehlermeldung:
local response = json.decode(json)
local hour = response.sunrise.hour
local minute = response.sunrise.minute
fibaro:debug("Sonnenaufgang"..hour ":" ..minute" Uhr")
Fehlermeldung:
[DEBUG] 12:59:16: [1;31m2016-09-29 12:59:16.277997 [ fatal] LUA error: /usr/share/lua/5.2/json/decode.lua:74: bad argument #1 to 'match' (string expected, got table)
Was mache ich falsch!?
Hier mein Code und darunter der response aus dem debug:
--[[
%% properties
%% events
%% globals
--]]
local http = net.HTTPClient()
http:request('http://api.wunderground.com/api/Your_Key/astronomy/q/Australia/Sydney.json', {
options = {
method = "GET",
},
success = function (response)
fibaro:debug(response.data)
end,
error = function (err)
--fibaro: debug ("Error:" .. err)
end
})
Debug:
[DEBUG] 12:27:46:
[DEBUG] 12:27:46: {
[DEBUG] 12:27:46: "response": {
[DEBUG] 12:27:46: "version":"0.1",
[DEBUG] 12:27:46: "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
[DEBUG] 12:27:46: "features": {
[DEBUG] 12:27:46: "astronomy": 1
[DEBUG] 12:27:46: }
[DEBUG] 12:27:46: }
[DEBUG] 12:27:46: , "moon_phase": {
[DEBUG] 12:27:46: "percentIlluminated":"2",
[DEBUG] 12:27:46: "ageOfMoon":"28",
[DEBUG] 12:27:46: "phaseofMoon":"Waning Crescent",
[DEBUG] 12:27:46: "hemisphere":"North",
[DEBUG] 12:27:46: "current_time": {
[DEBUG] 12:27:46: "hour":"12",
[DEBUG] 12:27:46: "minute":"25"
[DEBUG] 12:27:46: },
[DEBUG] 12:27:46: "sunrise": {
[DEBUG] 12:27:46: "hour":"7",
[DEBUG] 12:27:46: "minute":"31"
[DEBUG] 12:27:46: },
[DEBUG] 12:27:46: "sunset": {
[DEBUG] 12:27:46: "hour":"19",
[DEBUG] 12:27:46: "minute":"14"
[DEBUG] 12:27:46: },
[DEBUG] 12:27:46: "moonrise": {
[DEBUG] 12:27:46: "hour":"5",
[DEBUG] 12:27:46: "minute":"37"
[DEBUG] 12:27:46: },
[DEBUG] 12:27:46: "moonset": {
[DEBUG] 12:27:46: "hour":"18",
[DEBUG] 12:27:46: "minute":"50"
[DEBUG] 12:27:46: }
[DEBUG] 12:27:46: },
[DEBUG] 12:27:46: "sun_phase": {
[DEBUG] 12:27:46: "sunrise": {
[DEBUG] 12:27:46: "hour":"7",
[DEBUG] 12:27:46: "minute":"31"
[DEBUG] 12:27:46: },
[DEBUG] 12:27:46: "sunset": {
[DEBUG] 12:27:46: "hour":"19",
[DEBUG] 12:27:46: "minute":"14"
[DEBUG] 12:27:46: }
[DEBUG] 12:27:46: }
[DEBUG] 12:27:46: }
[DEBUG] 12:27:46:
Danke für eure Hilfe!