Web json text decode

Hi!

The File.ReadfromFileName reads file OK. In File.gotText, the text is decoded with Web.jsonTextDecode, which returns the empty text.
I run this code in screen2.
A similar code in screen 1 works well.

regards

Boris

  1. You do not show that exercises.json is in your assets (or that it contains anything...)
  2. You do not show where/how you are calling getExercisesFile

I call it from Sreen 2 initialize. There is some kind of delay. In Notifier in File.GotText I see this json file, but in Screen2.initialize variable exercises_json is empty.
In run_1 procedure I add some code from Screen2.initialize.

Thank you.

Boris

You are calling the notifier here as well

image

this is before File1.GotText, so you would need to close the "first" notifier before you see the second one. Or better still just remove the blocks for the "first" one.

Notifier is only for debuging. Json file is read, decoded and assigned to global variable exercises_json.
In File.getText this variable is not empty, but in Screen.initalize this variable is empty.


It is very difficult to debug when you only show a part of your relevant blocks.

My guess is that you need to reorganise the order of your workflow:

Read file
Get file contents
Set contents to variable
Do other things with variable (contents)

Try moving everything after the procedure call getExerciseFile into the File1.GotText event (after you set the text to global exercises_json)

In initialize blocks you won't read the contents of the file, you just call the process of reading the file. The reading process itself takes longer than the app initialization process. After reading the data from the file, the got.text event is dispatched, in this event you need to handle your variables, not in the initialize block.

Export your .aia file and upload it here.

I just tried it and it works.

Thank you.

I moved the code (except File.read) from the initialization block to block File.gotText. However, it is strange, while in the initialization block TinyDB.getValue works fine and File.gotText does not.

It is not strange.

Getting data from tiny db is a synchronous method so the code waits to read from tinyDb, this reading is fast.

Reading from a file is an asynchronous method, it is moved to another thread as the main thread goes on and executes blocks in initialize. Once the file has been read in the second thread, the got.text event will be dispatched.

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