Work with json , i have a problem.

You must Login before you can answer or comment on any questions.

hello to all you guys! I wanted to make an app that was easy to update, and I immediately thought of the use of json.I watched and analyzed this example: example and this would be perfect for me, except in one case.

Always using the example of the link that I posted, I ask you this: I would not start that as soon as the application elements are not loaded from json, that's why I should be only the first time you download the application here from the AppStore and having the active connection may also be able to connect to the json file on my server. Then if the user starts the app one more time, maybe not having an active connection, how do you load the latest data from json file? Here I wanted to know if it was possible to use the json file to download updated data, only when there was an active connection (for example, I could put a button "update data"), and use default data inside the app when the 'user could not connect to the Internet. But once updated the app using the "update data" these data were saved as the default data within the application. In this way the application will always have the latest data.

Thank you and I hope I was clear.

1 Answer

Accepted Answer

I would start with a full copy of a default JSON file in your app.

Use a variable to reference its location through out your app. Then in the future (when a button is pressed, etc) you can change the variable to point to a downloaded version of the JSON file and apply the requisite changes.

— answered 9 months ago by Stephen Feather
answer permalink
28 Comments
  • You will need to be caching your remote JSON to the file system, or, depending on its size, maybe load it into a Ti.App.property.

    — commented 9 months ago by Stephen Feather

  • So in the meantime THANK YOU VERY MUCH for the GREAT answer!

    So if I understand correctly I should do so: - I create my json file - I put a copy of the json file on the server - And one inside the app

    • Within the app I create variables that I need, and fill this variable with data taken from local json.

    • When I press the button "update data", this variable change in value, taking data from json file server

    ok?

    — commented 9 months ago by nicolò monili

  • The JSON data is loaded into a variable at some point, so it doesn't matter if it comes from a local file into that variable or a remote file, or from a property where you stored the data.

    File Store

    1. first run, copy your packaged myfile.json to a location outside of the Resource directory so it can be writable. will have to set a flag/semaphore so you only do this on first install.
    2. load the json into a variable from the new location (not the one in resources)
    3. parse/use data as required
    4. download myfile.json from remote server, save over the myfile.json stored outside of Resource directory
    5. reload data from the updated json file
    6. refresh UI as needed

    — commented 9 months ago by Stephen Feather

  • Show 25 more comments

Your Answer

Think you can help? Login to answer this question!