![]() |
Parse json in javascript - Printable Version +- Virtuino Forum (https://virtuino.com/forum) +-- Forum: Virtuino (https://virtuino.com/forum/forumdisplay.php?fid=1) +--- Forum: Virtuino IoT (https://virtuino.com/forum/forumdisplay.php?fid=2) +--- Thread: Parse json in javascript (/showthread.php?tid=1409) |
Parse json in javascript - Joe - 09-06-2023 Hi, I want to parse the following json string: {"Time":"2023-09-06T13:38:56","BME280-76":{"Temperature":28.7,"Humidity":47.9,"DewPoint":16.6,"Pressure":1016.7},"BME280-77":{"Temperature":28.6,"Humidity":92.6,"DewPoint":27.3,"Pressure":1017.0},"PressureUnit":"hPa","TempUnit":"C"} The first javascript line gives already an error Code: var json = Virtuino.readValue("inputTag"); //Read inputTag value as String. ERROR: Unexpected identifier 'Time'. Expected ';' after variable declaration. If I run this: Code: const obj = JSON.parse(Virtuino.readValue("inputTag")); //Read inputTag value as String. the error is: ERROR: Unexpected identifier 'Time'. Expected ')' to end an argument list. I know I can use the 'Jason to Variable' script tool, but that would require more then 10 scripts to get all the variables. Any idea? THX Joe RE: Parse json in javascript - Joe - 09-12-2023 Hi, is there really no way to get a Json string into javascript? This is in V0 inputTag: Code: {"Time":"2023-09-09T19:05:35"} this javascript does't work: Code: //var inputValue='{"Time":"2023-09-09T19:05:35";' // this is working Need something like "Virtuino.readJson" Best regards, Joe RE: Parse json in javascript - iliaslamprou - 09-12-2023 Hi Joe, It took me quite some time to figure out how to resolve this issue. From the next update the function Virtuino.readValue will be able to read the Json message This is an example: Code: /* RE: Parse json in javascript - Joe - 09-13-2023 (09-12-2023, 09:41 PM)iliaslamprou Wrote: Hi Joe, Ilias, you are my hero! Sorry that this has stolen so much of you free time. All the best, Joe |