[Solved] Json Deserialize on Android doesn't work for me

Hi, I try to make an tiny android project & try to deserialize a Json file, but each time I have this exception :
“Unhandled Exception:
System.IO.DirectoryNotFoundException: Could not find a part of the path “/Platformer/Json/Level/document.json”.”
( You can find the project here : https://www.dropbox.com/s/ot4kkor0j27kt8q/Platformer.zip?dl=0 )

The json file called “document.json” :
{ "creator": "Thomas", "name": "Niveau 1" }

I also make an Json test project for a Window Project using this code, and it work fine.

protected LevelJSON GetLevelJSON(string psFileName) { LevelJSON myLevelJSON; Debug.WriteLine("TEST :"); Debug.WriteLine(File.ReadAllText(psFileName)); using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(File.ReadAllText(psFileName)))) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(LevelJSON)); myLevelJSON = (LevelJSON)ser.ReadObject(stream); } return myLevelJSON; }

And finally, there is one thing that confuses me, when I add the reference for the Json (for use : using System.Runtime.Serialization; ), the PC version & Android version isn’t the same. ( Maybe it doesn’t work because of that, but I have no idea … )
:
( I’m French, so my visual studio is in French :slight_smile: )

Also, I use in the both projects besides “using System.Runtime.Serialization;” :
using System.Text; using System.Text;
I spent my weekend to try different things and I’m stuck, I have no idea what is wrong.
Thank to reply if you have any idea about that.

  1. Filenames on PC are not case-sensitive, but they are case-sensitive on Android (also iOS). Double check that the filename is correct.

  2. You have to open files differently on Android, I don’t know how to use MemoryStream but heres an example of how to open a FileStream on Android:

Hope this helps, cheers!

1 Like

Every time I read the French word, Nom, I remember this:

1 Like

Hahaha funny ! I open the example on github, but can’t launch the project on any platform :confused:

1 Like

If you are talking about the github link I posted, yeah that project compiles to a class library :frowning:

1 Like

Ok :neutral_face:. I’m still stuck in the Json problem

YES ! :grinning:
After many tentative, it finally work !
I use :

using (var stream = Game.Activity.Assets.Open("document.json"))

, and I set the Build Action of the Json File into “AndroidAsset”. Thank again !