how to read a JSON File from the system.ResourceDirectory?

I create some levels as JSON Files and now wonder how I can use the loadsave.lua to load this files from a subfolder in the system.ResourceDirectory?

Is this possible somehow and will it work on all devices?

Hi @d.mach,

No. You need modify Rob Miracle’s  library.

Add new field to valid locations i.e

-- loadsave.lua local \_validLocations = {    [system.DocumentsDirectory] = true,    [system.CachesDirectory] = true,    [system.TemporaryDirectory] = true,    [system.ResourceDirectory] = true, }

To load ‘map.json’ from maps folder

loadsave.loadTable( 'maps/map.json', system.ResourceDirectory )

Note :

You should not create, modify, or add files to this directory. Doing so will prevent the device from verifying the integrity of your application; in some cases the device will treat your application as malware and refuse to launch it

See documentationfor more information.

Read more :

Have a nice day:)

ldurniat 

Thank you very much for your detailed feedback! Much appreciated!

When I use this to read json files there should be no problem with “Malware” detection, right? This is only an issue when files are changed (saved) in the resources directory, right?

One more thing: Is this code working on Android devices also because there is no resource directory there?

@d.mach, just a question, why not create a sqlite database instead of a json file? much easier to work with, since a database was designed…well…to organize information :slight_smile:

if you need to save/delete/update data you just need to copy your database do a temp/document directory and use it normality.

still don’t know why people use json files to organize data. I only use it on my webservices to send data from internet to my apps.

if you don’t know how to use sqlite, just ask :slight_smile:

I think so. This directory is read-only. See documentation.

Should work.

Hi @d.mach,

No. You need modify Rob Miracle’s  library.

Add new field to valid locations i.e

-- loadsave.lua local \_validLocations = {    [system.DocumentsDirectory] = true,    [system.CachesDirectory] = true,    [system.TemporaryDirectory] = true,    [system.ResourceDirectory] = true, }

To load ‘map.json’ from maps folder

loadsave.loadTable( 'maps/map.json', system.ResourceDirectory )

Note :

You should not create, modify, or add files to this directory. Doing so will prevent the device from verifying the integrity of your application; in some cases the device will treat your application as malware and refuse to launch it

See documentationfor more information.

Read more :

Have a nice day:)

ldurniat 

Thank you very much for your detailed feedback! Much appreciated!

When I use this to read json files there should be no problem with “Malware” detection, right? This is only an issue when files are changed (saved) in the resources directory, right?

One more thing: Is this code working on Android devices also because there is no resource directory there?

@d.mach, just a question, why not create a sqlite database instead of a json file? much easier to work with, since a database was designed…well…to organize information :slight_smile:

if you need to save/delete/update data you just need to copy your database do a temp/document directory and use it normality.

still don’t know why people use json files to organize data. I only use it on my webservices to send data from internet to my apps.

if you don’t know how to use sqlite, just ask :slight_smile:

I think so. This directory is read-only. See documentation.

Should work.