Api Error - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Api Error (/showthread.php?tid=2650) |
Api Error - arivera - 20.05.2020 Hello I am trying to read this data with the Api provided by the manufacturer and I am having problems as it gives me the following error. when I try to read item "1" Error de sintaxis en la linea 28: ')' expected near '.1' Assistant screenshot The first thing I have to do is comment on the following variables because otherwise I can't read anything Assistant screenshot --potencia = data.PAC.Values --total = data.TOTAL_ENERGY so that at least read the variable "day" and point only to the "Values" element so that it returns the 2 values in the "log" Where is the error, how could I read all the values of the elements? Thank you API { "Body":{ "Data":{ "DAY_ENERGY":{ "Unit":"Wh", "Values":{ "1":56350, "2":85580 } }, "PAC":{ "Unit":"W", "Values":{ "1":7018, "2":10434 } }, "TOTAL_ENERGY":{ "Unit":"Wh", "Values":{ "1":7979740, "2":6941850 } }, "YEAR_ENERGY":{ "Unit":"Wh", "Values":{ "1":4525021, "2":6941852 } } } }, "Head":{ "RequestArguments":{ "DeviceClass":"Inverter", "Scope":"System" }, "Status":{ "Code":0, "Reason":"", "UserMessage":"" }, "Timestamp":"2020-05-20T16:45:38+02:00" } } RE: Api Error - Daniel - 20.05.2020 Post your script and what do you get when you log data? RE: Api Error - Erwin van der Zwart - 20.05.2020 Hi, Are you trying to read this JSON direct (not possible to do, so your error might come from there) or do you have json.pdecode somewhere to convert it to a LUA table? What i see in first sight is your table has other fields, first of all Data is with a capital D so the fields should be tablename.Data.PAC.Values but i also see a main wrapping table called Body so shouldn’t your code be tablename.Body.Data.PAC.Values ? BR, Erwin RE: Api Error - arivera - 21.05.2020 (20.05.2020, 18:00)Erwin van der Zwart Wrote: Hi,Hi Erwin I have a json.decode somewhere to convert it to a LUA table effectively the problem was capital D but when I try to read the Value of field 1 with the following command Line 21 day = data.Body.Data.DAY_ENERGY.Values.1 "Body":{ "Data":{ "DAY_ENERGY":{ "Unit":"Wh", "Values":{ "1":56350, "2":85580 it gives me a syntax error Error de sintaxis en la linea 21: ')' expected near '.1' If I execute the sentence as follows Line 21 day = data.Body.Data.DAY_ENERGY.Values I open the registration window I see the 2 values perfectly How can I read the value 1 and 2 from the table? I do not know how to send a screenshot to send the script because when I give the insert image icon it asks me for a URL or how to send a screenshot Thank you RE: Api Error - Daniel - 21.05.2020 You can paste it as text or use attachment to add image. Log data and paste the result here RE: Api Error - Erwin van der Zwart - 21.05.2020 Hi, Try: data.Body.Data.DAY_ENERGY.Values[1] or data.Body.Data.DAY_ENERGY.Values['1'] BR, Erwin RE: Api Error - arivera - 21.05.2020 (21.05.2020, 19:24)Erwin van der Zwart Wrote: Hi, Thank you very much that was the mistake it's ready |