problems exporting/reading json files to android

tryingmybesttryingmybest Posts: 3Member

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 Im not sure if the files just arent expotred 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 doesnt exist it`s still the same exception.
I attached the script where it all happens below

Can anyone provide some help please?


Tags :

Best Answer

  • TwistedTwiglegTwistedTwigleg Posts: 2,663
    Accepted Answer

    I think you need to use Godot's File class if you want to use paths like user://. So instead of System.IO.File.ReadAllText("user://ItemList.json");, you instead will need to use something like (untested):

    var ItemListFile = new File();
    ItemListFile.Open("user://ItemList.json");
    var ItemList = ItemListFile.ReadAsText();
    

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 2,663Admin
    Accepted Answer

    I think you need to use Godot's File class if you want to use paths like user://. So instead of System.IO.File.ReadAllText("user://ItemList.json");, you instead will need to use something like (untested):

    var ItemListFile = new File();
    ItemListFile.Open("user://ItemList.json");
    var ItemList = ItemListFile.ReadAsText();
    
  • tryingmybesttryingmybest Posts: 3Member

    ohh thank you so much for helping out!!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file