Merbs Anda Merbs Anda - 4 months ago 26
Android Question

How can I use json inside my resources folder?

I'm using Visual Studio with Xamarin and wish to store a json file inside of my resources folder.

I need to get the path, deserialize it, then load the data asynchronously. I've looked around, but can't find any useful examples. Is this possible?


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).