I’m pretty new to Unity as well so I can’t fully answer your question… I would assume LINQ would work fine but I can’t make any guarantees on JSON.NET.
As for the questions, 5,000 doesn’t seem like a tremendous amount. It all depends on how you want to handle them. If there are no categories, you can store them all in once place. What you’ll probably want to do is read in all of the questions and deserialize them to a collection, like IEnumerable
So you might have a class that looks like this:
public class Question
{
public string QuestionText = "Why did the chicken cross the road?";
public int AnswerIndex = 1;
public string[] Answers = new[]
{
"To visit his grandma at KFC",
"To get to the other side"
};
public int Difficulty = 4;
}
When you use JsonConvert.SerializeObject(myQuestion); You’d get a Json formatted representation of the object. You can even serialize a List so you’ll have them all in one place. When you deserialize your object:
var questions = JsonConvert.Deserialize<List<Question>>(stringOfQuestionData);
You’ll end up with a List that you can work with. Now if you want to find all questions with a difficulty of 2 you could say:
var diff2 = questions.Where(q => q.Difficulty == 2);
Or you could order them in order by difficulty:
var byDifficulty = questions.OrderBy(q => q.Difficulty);
Maybe you want to order them by category (and you have a CategoryId property) and then difficulty:
var ordered = questions.OrderBy(q => q.CategoryId).ThenBy(q => q.CategoryId);
Or find questions with a specific category:
var targetQs = questions.Where(q => q.CategoryId == 2);
You could do any number of things. If you’re going to have a lot of questions there are some considerations in how you’ll want to store the data. IO is an expensive operation so you’ll want to load in what you need and not load each on-demand unless performance isn’t critical. If each question only has one category ever, you can just have a CategoryId property. You could store your questions in different files numbered with the correct category so you only load the ones you need, or you can store all of your categories in one file and all of your questions in another. Give each category its own id. To support multiple categories per question, store a List in the Question that tells what categories it is in. Load all of your questions into one List and all of your categories into one List.
So let’s say your Question class has a CategoryList property that’s a List And your Category class has a CategoryId property that’s of type int. Now you pick a Category that has a CategoryId of 3. Here’s how you’d find all questions associated with that category:
var categoryQs = questions.Where(q => q.CategoryList.Contains(3));
It really just completely depends on how you want to implement it.