Error checking Get Property of Object

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?

1 Like

Try this

image

Happy Coding

1 Like

this also works
object

1 Like

Could you share your code so we can see where you went wrong?

1 Like

Please share your code so that glitches can be fixed, and yeah the link is showing error too, please fix this as well.

1 Like

@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
image
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
image
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.

1 Like

Thank you! This did work, @jaythemanchs, to catch the error when the properties are not part of the returned JSON.