Parse JSON from local file on mobile [SOLVED]

So, I’m trying to have a database in a local file on Android, read it, and parse it into something I can use.

I’d like to understand why something like this doesn’t work:

The “Load text” works fine and everything I need is in the “datafile”, and if I just paste that into the JSON string, it works, but if I do the above, I get an “Unexpected token in JSON at position 0” error. Does not seem to matter what I actually have in the file.

I also tried sending a GET request, but I don’t know how to do that for a local file on mobile, and it feels… wrong.

Where am I messing up?

From the GDevelop wiki:

I do not see how that is relevant? Like I said, I am trying to do this on Android (mobile).

The line that says “Mobile games and web games are not currently supported”?

Is the string not already loaded into a variable? Is that not stored in memory? I am not looking to access the file system on mobile, just what is packaged inside the apk. That is not possible either?

How are you including it in the .apk? You can check if it is in there by changing the apk extension to a .zip, and exploring the zip file.

But the .apk is installed on the mobile device, and even if the file were there, the filesystem commands don’t work on mobile platforms.

It’s packaged under /assets like all the other assets. I’m not trying to alter it or anything. I only need to read it once at game start. So why can I read a jpeg, but not that? It’s just text, that I’m trying to convert into JSON and then do stuff with. I can’t imagine why this would not be possible? Is there some other command for this? Or am I fundamentally not understanding something about this system?

You can do this, just not using the filesystem actions ;p Those are for reading and writing files at runtime, not at build time, and only work on PC builds. To load a JSON at build time, use the “Load JSON Resource” extension.

2 Likes

UUgghh. OK… Got it done now! In all the searching I did around the internet, I could never find a reference to that extension! For anyone reading this, the exact name of the extension is “JSON Resource Loading”. Thanks all for your help!

2 Likes