Web API goes white screen after getting data

Hi guys,
My app is using the train company public API, and the only thing the user need to do is to enter Line name and Station name, the app will get the estimated arrival time for trains of that specific station.

I am wondering why when ever the button is pressed and the data is got from Web API, the screen goes white immediately on Thunkable Live and downloaded app in iOS.

here are my simple code, user simply enter line and sta parameter and the app call the data from https://rt.data.gov.hk/v1/transport/mtr/getSchedule.php?line=XXX&sta=XXX and set the data to label 1.

For your ref:
Next Train API API Specification

Anyone know how can I fix this, thanks a lot!

White screen means that there is an error in reading of object data from the object blocks. Sometimes API responses won’t always returns consistent data. You should check if the object contain the property you are reading first using “does __ contains __” blocks before reading the data to prevent the white screen hang.

But for your case, I notice an error in reading the data. comparing your blocks and the PDF JSON response reference, you missed out “TKL-TKO” object before trying to read “UP”. and By the way, under “UP” there are square brackets which means you need to use list blocks to access the the items, even if there is only one item.

4 Likes

Thanks you so much for your information, I will have a try based on your recommendation. :slight_smile:

@gobassky The “does contain” block is a great suggestion! I’ve been struggling to know whether or not I am parsing JSON data correctly but now I have a way of checking each step. Thanks!

1 Like

@gobassky I’m wondering if you know how to retrieve data from a JSON object that has backslashes in the property names?

Here’s the project I’m testing, as described below:

https://x.thunkable.com/copy/bba5f49b89956f99acfa2b0c3fa66552

When I go to this url: https://www.purpleair.com/json?key=52AUOV78J1OX3R2J&show=21371, the formatted data I want is in response–>results[1]–>Stats–>v1

The url creates this JSON:

{“mapVersion”:“0.17”,“baseVersion”:“7”,“mapVersionString”:"",“results”:[{“ID”:21371,“Label”:“Sbirdee”,“DEVICE_LOCATIONTYPE”:“outside”,“THINGSPEAK_PRIMARY_ID”:“649474”,“THINGSPEAK_PRIMARY_ID_READ_KEY”:“52AUOV78J1OX3R2J”,“THINGSPEAK_SECONDARY_ID”:“649475”,“THINGSPEAK_SECONDARY_ID_READ_KEY”:“Y2BNKU6L0YFESCBY”,“Lat”:38.085761,“Lon”:-122.566461,“PM2_5Value”:“81.77”,“LastSeen”:1598446433,“Type”:“PMS5003+PMS5003+BME280”,“Hidden”:“false”,“DEVICE_BRIGHTNESS”:“15”,“DEVICE_HARDWAREDISCOVERED”:“2.0+BME280+PMSX003-B+PMSX003-A”,“Version”:“6.01”,“LastUpdateCheck”:1598443311,“Created”:1544549222,“Uptime”:“198480”,“RSSI”:"-66",“Adc”:“0.01”,“p_0_3_um”:“13325.73”,“p_0_5_um”:“3832.95”,“p_1_0_um”:“766.7”,“p_2_5_um”:“75.8”,“p_5_0_um”:“11.79”,“p_10_0_um”:“3.95”,“pm1_0_cf_1”:“77.7”,“pm2_5_cf_1”:“123.45”,“pm10_0_cf_1”:“138.39”,“pm1_0_atm”:“51.02”,“pm2_5_atm”:“81.77”,“pm10_0_atm”:“91.36”,“isOwner”:0,“humidity”:“59”,“temp_f”:“68”,“pressure”:“1009.94”,“AGE”:1,“Stats”:"{“v”:81.77,\“v1\”:87.06,“v2”:80.05,“v3”:77.98,“v4”:79.71,“v5”:53.03,“v6”:11.95,“pm”:81.77,“lastModified”:1598446433467,“timeSinceModified”:119989}"},{“ID”:21372,“ParentID”:21371,“Label”:“Sbirdee B”,“THINGSPEAK_PRIMARY_ID”:“649477”,“THINGSPEAK_PRIMARY_ID_READ_KEY”:“W62KA2YR9E5GUYFO”,“THINGSPEAK_SECONDARY_ID”:“649479”,“THINGSPEAK_SECONDARY_ID_READ_KEY”:“30PAG36NS1DTWWLA”,“Lat”:38.085761,“Lon”:-122.566461,“PM2_5Value”:“79.94”,“LastSeen”:1598446433,“Hidden”:“false”,“Created”:1544549222,“Adc”:“0.01”,“p_0_3_um”:“13866.0”,“p_0_5_um”:“3953.7”,“p_1_0_um”:“691.52”,“p_2_5_um”:“69.39”,“p_5_0_um”:“9.39”,“p_10_0_um”:“1.57”,“pm1_0_cf_1”:“76.39”,“pm2_5_cf_1”:“120.91”,“pm10_0_cf_1”:“127.5”,“pm1_0_atm”:“50.2”,“pm2_5_atm”:“79.94”,“pm10_0_atm”:“84.3”,“isOwner”:0,“AGE”:1,“Stats”:"{“v”:79.94,“v1”:84.56,“v2”:77.66,“v3”:75.66,“v4”:77.9,“v5”:52.09,“v6”:11.78,“pm”:79.94,“lastModified”:1598446433467,“timeSinceModified”:119989}"}]}

The forum software strips out the backslashes but I’ve added them back in in the bold section above.

Do you know how I can access Stats → {\“v1\”} ?

I’ve tried including quotes and backslashes, including just quotes, and just using v1 by itself but they are all “undefined” even though my does contain is true:

And I’ve tried it with and without the generate JSON from object block.

But it still returns “undefined.”

You forgot to use one block. Here is a working version.

1 Like

Thank you! I swear I tried that but… I must not have. It works. :slight_smile: