0 votes

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?

asked Jun 28 in Engine by tryingmybest (12 points)

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

3 Answers

0 votes

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);
answered Jun 29 by indicainkwell (108 points)
0 votes
answered Jun 29 by rakkarage (809 points)
0 votes

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.

answered Jun 29 by tannhauser_gate (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.