Loading Data from json file if 404 Error

So I'm trying to set the app up so if the app is unable to connect to a network connection, then it will load the values from a .json file.

Am I on the right track and what will be the best way to achieve this?
The Set response code is for testing at the moment that the offline version works.


did you upload the easy.json file as an asset?


That worked changing it to an asset. Now I just need to get it to read the objects in the json file

In that block of code I've already for the variable api_results.
If possible, I would still like to channel the variable.

As you see in the image below, I'm using the api_results to output to labels.

If the json files content can be channelled into the api_results variable, that would make this easier

So it will read the json via and pipe the content into this api_results variable to continue to be used through the app without the need to create a whole to block code to process the offline json file compared to polling the API

That's what I'm thinking I want to do but if there is a better way to do it, please let me know.
I'm still learning all this.

I still don't understand what you're trying to do
but the point is, what do you want?

I see you still have a json full of uriEncode characters. You need to fix that.

What I need to do is pull data from an API but if I don't have an internet connection, then I need to pull data from a json file.

okay now, which one you want to pull

Json can be fixed only if data is edited and saved as file in assets otherwise if used online it is full of uriEncode characters because of API. An example


I'm able to pull data from the API. I have that working to some extent.
What I'm trying to do now, is the offline component.

So if I get a response code of 404, I want to pull data from a json file.

Then remove the encode parameter ?


1 Like

omg, I wish I knew that before.

Missed that :blush: so simple solution !

If it is an asset in Media, the file name should be //easy.json.

Okay I got it, so you want to fetch content from easy.json which is in assets right?, am I right?

Yes, that's what I'm trying to do

1 Like

Something like this maybe ?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.