i don’t know if I’m explaining it right but what i want is to be able to save 3 lists of strings but have them separated based on time. The idea is to store some strings for each day and save them into a json so i can search for the date and display them into a calendar.
My try was like so
[Serializable]
public class TimeStamp
{
public string CreatedDate;
public List<Entries> day = new List<Entries>();
}
[Serializable]
public class Entries
{
public List<string> names = new List<string>();
public List<string> location = new List<string>();
public List<string> info = new List<string>();
}
which then i saved like so
string json = JsonUtility.ToJson(timeStamp);
try
{
timeStamp.CreatedDate = DateTime.UtcNow.ToLocalTime().ToString("dd-MM-yyyy HH:mm");
File.WriteAllText(Application.persistentDataPath + "/Journal.json", json);
Debug.Log("Data Saved");
}
catch (Exception e)
{
Debug.Log("Error Saving Data:" + e);
throw;
}
Which does save everything i need but its not separated by the date, trying to explain it the way i think of it is that i want the date to be the “header” of the Json so in one Json file i would have all entries for each day and also i made them into a list so i can add or remove strings.
So later on when i want to add something i would search for the date and access the names list for instance and .Add() my string to that list
In a rather crude way this is how i would like my json to look like:
entries
[
"date"[
list1 = []
list2 = []
list3 = []
]
]
The way i feel like it should be is something like this
[Serializable]
public class Roots
{
public TimeStamp timeStamp;
}
[Serializable]
public class TimeStamp
{
public List<Entries> entries;
}
[Serializable]
public class Entries
{
public List<string> names = new List<string>();
public List<string> location = new List<string>();
public List<string> info = new List<string>();
}
which gives a json like this
{
"Entries": {
"Timestamp": [ // this entry here //
{
"names": "",
"location": "",
"info": ""
}
]
}
}
but how can i make that Timestamp be a string or a date?