skip to Main Content

Good day dear developers, I really need your help. I want to make an app in Xamarin. In which I added some text data, and it is saved in this application. I need this information to be in the application, and I could get it without the Internet. I understand that you need to use JSON. I really want you to at least give a little hint on how I can store information using JSON in my Xamarin application. Thanks a lot!)

I tried to find information on Google, but there is a lot of superfluous and inappropriate

2

Answers


  1. Depending on your data an easy way could be to use Preferences from Xamarin.Essentials which allows you to store key/value pairs: link to description

    Another option would be to save files with JSON as you mentioned already. You create a class which holds your data and then serialize/deserialze the objects to files and from files. For this you can use the Newtonsoft.Json which is a nuget package that you can install.

    If you have a MyData class and an data object it would look like this:

    Serialize:

    File.WriteAllText("fileName", JsonConvert.SerializeObject(data));
    

    Deserialze:

    var myData = JsonConvert.DeserializeObject<MyData>(File.ReadAllText("fileName"));
    
    Login or Signup to reply.
  2. Different platforms has their own file system. For example, iOS limits our access to the file system, which is called Application sandbox. To save or load files, you could learn some basic info first:

    for iOS, refer to File system access in Xamarin.iOS.

    for Android, refer to File Storage and Access with Xamarin.Android

    Xamarin forms provides several ways to use Xamarin forms local data storage. First is use File Handling just as Mario K mentioned. For Serializing JSON, you could refer to Serializing JSON.

    Another is that you could use SQLite database engine which allows Xamarin.Forms applications to load and save data objects in shared code. More info, you could refer to Xamarin.Forms Local Databases.

    I think you could first check these documentation and decide which method you prefer to use. If you still have questions, feel free to ask.

    Hope it works for you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search