Need JSON/Web API Help

So, I have a script on my server that generates a .json file. The contents of that file are output like this:

[{"bz_5_value":"0.56","bt_5_value":"3.77","density_5_value":"3.62","speed_5_value":"443.4","bz_15_value":"0.93","bt_15_value":"3.81","density_15_value":"3.80","speed_15_value":"440.1","bz_30_value":"0.62","bt_30_value":"3.90","density_30_value":"3.79","speed_30_value":"438.8","bz_45_value":"0.82","bt_45_value":"4.16","density_45_value":"4.08","speed_45_value":"438.1","bz_60_value":"1.07","bt_60_value":"4.26","density_60_value":"4.27","speed_60_value":"440.1"}]

I then have the following blocks:
F03068B4-1925-42AF-83BF-9A3CC273D667

I want the text set for each of the values returned. However, when I call the API and access these variables, my text is set to null. I am not sure what I am missing here and why my .json file is not returning anything. Is there something special I need to do? This is a static .json file that is updated dynamically by a PHP script. So, any time the PHP script is called, it updates the .json file with current data. I should then be able to pull this static .json file into the app using the Web API component. I’m not sure where I’m going wrong on this. Can anyone see what’s causing this to return null?

3 Likes

This is how you should do it

3 Likes

Hi! Try this -


The JSON response you are is an array, as it has [ ] in it. You need to access the first element of the array from the object first, then add the property name. Let me know if this works :+1:

Edit: @muneer I missed you reply :sweat_smile: @ronnie both of our replies are based on the same approach btw.

3 Likes

@kartik14 I tried this:

A3F16506-BF29-427C-879D-4BD7CAF839CE_4_5005_c

As soon as the web app loads, it immediately flashes to a blank white screen…

1 Like

It’s gotta be a problem with my JSON. I just tested another reputable JSON source with your solutions and it works. I’ll work it out on my script.

Thanks for the assistance!

3 Likes

The preferable approach is to do it this way

You are here handing most conditions that you expect your users could come across which are:

  • There is a technical error preventing the execution of the API call
  • The API call resulted in a data retrieval problem

This should prevent the blank screen issue.

3 Likes

I would have arrived of some semblance of that eventually, because I wouldn’t want a user to think it’s broken. I typically throw “N/A” text in just so they see something and know the data is not there.

And, I did discover it was a problem with my script. No idea why, since I encoded the text as JSON. However, I discovered that the static file needed to be decoded and then encoded as JSON again. Once I did that, it worked like a charm!

3 Likes

Glad to hear that it’s solved now. :blush: Happy Thunking!

3 Likes