Merbs Anda Merbs Anda - 1 year ago 64
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download