How to save data with JSON in a Xamarin app? - json

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

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"));

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.

Related

Storing and loading data from react-native calendar to a JSON file

I'm currently thinking of a concept for a react-native app where people add events over a period of time like a diary/log. These events need to be exported and for security and privacy reasons I don't want to use a database. I've read you can use JSON files as a storage method, too.
How can I store data from the app to a JSON file and load the data from the JSON file back in the app? Don't need any code, helpful articles or webpages are appreciated
Assuming that you already have all the app data into a json, its rather simple.
Decide where to store the appdata.json, lets call it APP_DATA_PATH
Find a library to read/write files (I've only used expo-file-system)
On app boot, check if APP_DATA_PATH exists, if it does read the file and load into app, if not assume its a new user
Whenever app data changes, write the changes to APP_DATA_PATH

Storing database json file in optimal way for react native app

I’m using react native, redux and firebase and I have a 1 MB database export that contains food nutritional information from the Canadian Nutrition File database.
This data will never change and is used in a FlatList users can search and import from.
What’s the optimal way for me to store this for my users to access as fast as possible when searching?
I am thinking of simply including the json file with my other source files and calling it from there using require.
But since I have firebase and redux all setup I wondered if it made more sense for whatever reason to consider those options instead.
Thanks in advance for any input.
Since you are already using redux, i'd go for adding the json content to the store on app init/mount so you can get it easily from everywhere.
Another options i'd consider:
Import, parse & render the JSON file stactically on runtime (as it never changes);
Use the AsyncStorage to make it available in local database but outsite the redux store thing.

Save Json to online database GAE or Firebase

I am new to JSON and online databases. I have learned the basics of using .js files and manipulation on them. But I have no clue how to save them onto GAE or Firebase databases.
1)My question is, are every online databases uses JSON differently when they store them?
I have no idea what it looks like storing onto an online database so
2)Can you give me an example of JSON stored in Firebase or GAE. Links to tutorials are also helpful.
Firebase is a true "online database" in a sense that you can save/retrieve/query data to it, without actually writing any code on the server. As such, it is close to Backend as a Service offerings, such as Parse, Kinvey, etc.. Search the web to find more services and compare features that you need.
OTOH, GAE is an application platform - you will need to write server-side code to create any functionality.
As for examples: please RTFM.
GAE's ndb datastore API has a JsonProperty:
https://cloud.google.com/appengine/docs/python/ndb/properties
It's easy to store a JSON object as a StringProperty, using json.loads, json.dumps to parse. For a simple list, you can use a StringProperty, and giving it the repeated=True tag:
https://cloud.google.com/appengine/docs/python/ndb/properties#repeated

ListView and Data Models - Blackberry

I'm developing for the Blackberry 10.
I'm attempting to save and load a JSON data model into a listview in my app. It loads up initially via a couple lines of C++ in the app.cpp file before switching control to the QML file. However, I don't know how to save new cells into this JSON database. I don't know how to reload the ListView after I save. Finally, I don't know the restrictions regarding what I can and cannot save in a JSON database. Can anyone offer some assistance? Should I even be using a JSON model or should it be a QML or even XML? Thanks for all your help.
Some more information about what you are doing here would be helpful in order to provide an answer. JSON is a format used to contain and represent objects in a string, it is not a database. Typically working with a ListView requires creating a ListModel that contains your data and is rendered by the ListView. When working with a ListModel you have access to a variety of functions as documented at http://harmattan-dev.nokia.com/docs/library/html/qt4/qml-listmodel.html . It is not clear from your question what you are actually doing though I would suggest posting your code to make everything clear.

Where should I store custom permissions for my web app

I'm wondering where is the ideal place to store custom permissions in my web applications.
For example I have the following permissions:
AdminPermission
ReadPermission
WritePermission
At the moment I store these in the static utilities class as the constant string type objects.
Thank you
Somehow I guess you are talking about a Java app. You could try to externalize these resource in files, like in Tomcat (e.g. tomcat-users.xml).
Decided to go for a database approach with enums referencing records in xml config.