problems exporting json files to android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tryingmybest

Hi everyone hope you are having a good day/night.

I’m trying to read some data from a JSON file using

var ItemList = System.IO.File.ReadAllText(“user://ItemList.json”);

and I’m not sure if the files just aren’t exported at all or if I’m using the wrong path.

if I use the initial path like “ItemList.json” I get an unauthorized access exception on android, but it works on windows.

I changed it up to “user://ItemList.json” and now its just directory not found on both platforms. Even if I create a new file in case ItemList.json doesn’t exist its still the same exception.

Can anyone provide some help, please?

try rename to txt and remove .import if there is one

rakkarage | 2020-06-29 02:57

:bust_in_silhouette: Reply From: indicainkwell

The user:// protocol specifies a virtual directory that is only available with Godot API’s. I’m not sure of the correct symbol names for c#, but try:

var path = GD.ProjectSettings.GlobalizePath("user://ItemList.json");
var itemList = System.IO.File.ReadAllText(path);
:bust_in_silhouette: Reply From: tannhauser_gate

On the Export panel, go to the Resources tab, add ‘*.json’ in ‘Filters to export non-resource files/folders’ to enable exporting JSON files (as they are not treated as game resources). If not doing so, your game could only find JSON files successfully on PC but not on Android.

This is the correct solution to the problem. Thanks.

easwee | 2020-08-18 15:57

I registered just to upvote. thanks for this answer.

ando2099 | 2021-12-11 18:26

Me too. registered just to upvote. thanks for this answer.

rookiegamie | 2022-07-30 14:44

:bust_in_silhouette: Reply From: rakkarage

maybe related?