'Where do you store json files in a Xamarin forms app for ios and android apps

I'm new to Xamarin Forms and would like to include some read-only data in a json file to be deployed with the package that will be used as a local data store. How do you add this resource to the respective project types? ie iOS and Android.



Solution 1:[1]

You can put the json file in the Froms file directory, then click the file->Properties->Build Action to select Embedded resource.

You can get it using the code below:

var resourcePrefix = "MyApp.";//your project name.
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(MainPage)).Assembly;
Stream stream = assembly.GetManifestResourceStream(resourcePrefix + "aaa.json");//your json file name
using(var streamReader = new StreamReader(stream))
{
    var reader = streamReader.ReadToEnd();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wen xu Li - MSFT