Hey all!
I have a quick question about an issue I’m having about JSON deserialization.
Before, you say anything, yes, I know Newtonsoft is better. As of right now, I just need something lightweight.
I have a JSON file that looks like this:
{
"names": {
"firstNames": [
"Abigail", "Adam", "Adrian", "Aiden", "Alexander", "Alice",
"Amelia", "Andrew", "Anna", "Aria", "Ariana", "Asher",
"Benjamin", "Bella", "Blake", "Brianna", "Brooklyn",
"Caleb", "Cameron", "Charlotte", "Claire", "Connor",
"Daniel", "David", "Dylan",
"Eleanor", "Elizabeth", "Ella", "Emily", "Emma", "Ethan",
"Evelyn",
"Faith", "Finn", "Franklin",
"Gabriel", "Grace",
"Hannah", "Harper", "Henry",
"Isaac", "Isabella", "Isaiah",
"Jack", "Jacob", "James", "Jason", "John", "Joseph", "Joshua",
"Julia", "Julian", "Justin",
"Katherine", "Kevin", "Kylie",
"Liam", "Lily", "Lucas", "Lucy",
"Madison", "Mason", "Matthew", "Michael", "Mia",
"Nathan", "Nicole", "Noah",
"Oliver", "Olivia", "Owen",
"Penelope", "Peter",
"Quinn",
"Rachel", "Rebecca", "Riley", "Ryan",
"Samantha", "Samuel", "Sarah", "Sophia", "Sophie", "Steven",
"Thomas", "Tyler",
"Victoria",
"William",
"Zachary", "Zoe"
],
"lastNames": [
"Adams", "Alexander", "Allen", "Anderson", "Andrews",
"Bailey", "Baker", "Barnes", "Bell", "Bennett", "Brown",
"Campbell", "Carter", "Chapman", "Clark", "Collins", "Cooper",
"Davis", "Diaz", "Dixon",
"Edwards", "Ellis", "Evans",
"Ferguson", "Fisher", "Foster", "Freeman",
"Garcia", "Green", "Griffin",
"Hamilton", "Harris", "Harrison", "Hart", "Harvey", "Henderson",
"Hill", "Holmes", "Howard",
"Jackson", "James", "Jenkins", "Johnson", "Jones",
"Kelly", "Kennedy", "Kim", "King", "Kumar",
"Lee", "Lewis", "Lopez",
"Martinez", "Miller", "Mitchell", "Moore", "Morgan",
"Nelson", "Parker", "Patterson", "Patel", "Peterson", "Phillips",
"Ramirez", "Reed", "Richardson", "Rivera", "Roberts", "Robinson",
"Rodriguez", "Rogers",
"Sanders", "Scott", "Smith", "Stevens",
"Taylor", "Thomas", "Thompson",
"Walker", "Washington", "White", "Williams", "Wilson", "Wood",
"Young"
]
}
}
My object looks like this:
[System.Serializable]
public class Names
{
public List<string> firstNames;
public List<string> lastNames;
}
And deserilizing the JSON file looks like this:
Names names;
private void Start()
{
names = new Names();
names = JsonUtility.FromJson<Names>(nameFile.text);
}
However, each list gets a count of zero after the JSON file is deserialized.
Any thoughts why this could be?