Merbs Anda Merbs Anda - 2 months ago 9
JSON Question

how to use json inside my resources folder?

I'm using visual studio C# xamarin. I wish to store my json file inside my resources folder. Get the path, Deserialize it then load the data asychronously. I've been wrapping my head around bout this one.. I've done researches and I couldn't find any useful examples. Is this really possible?

Answer

Put the file under the "Assets" folder and use the following code to access it:

// to read from assets folder 
string content;
AssetManager assets = this.Assets;

using (StreamReader sr = new StreamReader (assets.Open ("file.json")))
{
   content = sr.ReadToEnd ();
}

// JSON is now in "content"

Afterwards you can pass the string to a JSON parser. You can find more information on this topic in the Xamarin documentation (=> Reading assets).