Hello - I am building an app that calls the https://civicinfo.googleapis.com/civicinfo/v2/representatives api. Depending on what the user enters in the input field, when it is used as a parameter to the api, sometimes the resulting JSON will not contain all the properties. Then when I call ‘get property of object’ with the expected property name, the app crashes. How do I capture the exception or query on the property without the application crashing?
Try this
Happy Coding
this also works
Could you share your code so we can see where you went wrong?
Please share your code so that glitches can be fixed, and yeah the link is showing error too, please fix this as well.
@mpokrzywinskimc6ua
There is no easy way to know if the property exists or not. The workaround presented by @jaythemanchs and @Balanced_Kitchen actually works but will make your code too long and too involved.
The best workaround I found is to use
which will give you a list of all properties in the object. You can then easily check the availability by using the blocks in the list drawer
which you can verify all required properties before displaying the contents.
With this method you can have a function that does the checking of all required properties and then you display the values of those available properties only.
Thank you! This did work, @jaythemanchs, to catch the error when the properties are not part of the returned JSON.