I'm just starting with LUA I have a problem with the API and script.
Address to API http://powietrze.malopolska.pl/_powietr ... a&ci_id=23
My script that will not process data
Code: Select all
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
local config=assert(io.popen('curl http://powietrze.malopolska.pl/_powietrzeapi/api/dane?act=danemiasta&ci_id=23'))
local location = config:read('*all')
config:close()
local jsonLocation = json:decode(location)
d1 = jsonLocation.dane.actual.details.0.par_desc
d2 = jsonLocation.dane.actual.details.0.g_nazwa
d3 = jsonLocation.dane.actual.details.1.par_desc
d4 = jsonLocation.dane.actual.details.1.g_nazwa
d5 = jsonLocation.dane.actual.details.2.par_desc
d6 = jsonLocation.dane.actual.details.2.g_nazwa
print('Lat: '..d1)
d1 = jsonLocation.dane.actual.details.0.par_desc
d2 = jsonLocation.dane.actual.details.0.g_nazwa
d3 = jsonLocation.dane.actual.details.1.par_desc
d4 = jsonLocation.dane.actual.details.1.g_nazwa
d5 = jsonLocation.dane.actual.details.2.par_desc
d6 = jsonLocation.dane.actual.details.2.g_nazwa
I have such a mistake
Malformed number near '.0.par_desc'
When he wants to download other data
d1 = jsonLocation.dane.city.ci_name
lua: test.lua:9: attempt to index field 'dane' (a nil value)
stack traceback:
test.lua:9: in main chunk
[C]: ?
Please help the new one.