public class Audioguia
{
public int id { get; set; }
public string name{ get; set; }
public string direction{ get; set; }
public string image { get; set; }
}
Hello, my boss has tasked me with adding an option to save a list of 'audioguides' (object for context above) as 'my audioguides' in an audioguide app. The user should be able to access this list at their convenience. The challenge here is that he wants to avoid using a database and has inquired whether this can be accomplished locally. I thought that this might be achievable by utilizing 'preferences.' However, I am encountering difficulties, particularly in serializing the data. I'm not even sure if it's possible to save a list of objects in this manner. Does anyone have insights on how to accomplish this, or can you confirm whether it is indeed possible? This is what I've attempted so far, but it hasn't been successful:
public class AudioguiaService
{
private const string KeyAudioguias = "Audioguias";
public List<Audioguia> GetAudioguias()
{
if (Preferences.ContainsKey(KeyAudioguias))
{
string audioguiaJson = Preferences.Get(KeyAudioguias, string.Empty);
if (!string.IsNullOrEmpty(audioguiaJson))
{
return JsonConvert.DeserializeObject<List<Audioguia>>(audioguiaJson);
}
}
return new List<Audioguia>();
}
public void AddAudioguia(Audioguia audioguia)
{
List<Audioguia> audioguias = GetAudioguias();
audioguias.Add(audioguia);
string audioguiaJson = JsonConvert.SerializeObject(audioguias);
Preferences.Set(KeyAudioguias, audioguiaJson);
}
}
You can write something like:
And add each Audiogia to separate entry in the settings:
And read each Audiogia separately, and add it to the list:
And this way you will not get errors because of the length. (Or you can serialize them in batches)
Or you can ignore your boss and do what programmers do, and place them in database.