I'm parsing some JSON data from a web-server but in-case the server is down or returns something unexpected I want my code to do something safe. I tried checking if the data was undefined but that produces the error:
Uncaught Error: Field or method "Hostname" does not already exist, and can't create it on undefined
So next I tried data.hasOwnProperty but this isn't implemented in Espruino's implementation of JSON :/
So I resorted to try catch which works just fine. Was this the right thing to do or should Espruino have some sort of has for JSON?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I'm parsing some JSON data from a web-server but in-case the server is down or returns something unexpected I want my code to do something safe. I tried checking if the data was undefined but that produces the error:
So next I tried data.hasOwnProperty but this isn't implemented in Espruino's implementation of JSON :/
So I resorted to try catch which works just fine. Was this the right thing to do or should Espruino have some sort of has for JSON?