- Home /
Loading similar items from JSON (How should I structure it?)
Hi
I haven't been able to find any good suggestions or tutorials on how to structure a JSON for lots of similar objects. I've seen a lot of saving entire game states, but in my case, I'm making a trading game and will need to load specific items, and later down the line will need to save the positions and inventories of vehicles.
Should I put everything in separate JSON files? A file with 1 extremely long list and an enum to know what index to reference? Or is there some other function entirely that I'm missing?
The general structure is something like this
{
"Wheat": {
"Icon": "Icon_Wheat",
"Weight": 10,
"BaseValue": 10,
"Type": 1,
"TimeUntilSpoilage": 40,
"SpoiltName": "SpoiltWheat"
},
"SpoiltWheat": {
"Icon": "Icon_Spoilt_Wheat",
"Weight": 10,
"BaseValue": 2,
"Type": 1,
"TimeUntilSpoilage": -1,
"SpoiltName": ""
}
}
Answer by unity_40139037 · May 28 at 05:07 PM
For anyone who finds this post; I've scrapped this system entirely. Instead of JSON I'm going to use CSV because they're much easier to manage large-scale. It's also more memory efficient, as the whole file doesn't need to read into RAM, only that line.
string line = File.ReadLines(Application.dataPath + "/Cargo.csv").Skip(ID).Take(1).First();
string[] values = line.Split('\u002C');
Then you can assign the elements into the object.