Hello,
I am still learning how to use Contentful, so I am a bit of a beginner. I’ve searched for a similar topic being asked, but I wasn’t able to find anything helpful.
I have a model, Episode
, that among its fields, contains a “References, many” called games
in it that contains a list of references to another model, QuizGameQuestion
.
Using C# and the .NET SDK, I am able to pull a specific episode and deserialize its properties into a C# class. It succeeds on all properties, except for the list of QuizGameQuestions. I know that it is able to pull the list of games
since the array/list inside Episode becomes the correct size (3 in this case), but all items contained in it are null. Here is the relevant code. Could someone tell me what I am doing wrong?
public class Episode
{
public string name {get; set;}
public string handle {get; set;}
public System.DateTime date {get; set;}
public List<QuizGameQuestion> games {get; set;}
async void Start()
{
// First populate gameReferences using a ServerConnector call to pull the episode from Contentful
ServerConnector serverConnector = FindObjectOfType<ServerConnector>();
Episode episode = await serverConnector.GetAllContentFromEpisode(*id omitted*);
name = episode.name;
handle = episode.handle;
date = episode.date;
games = episode.games;
//Then loop through and instantiate each game.
for(int i = 0; i < games.Count; i++)
{
Debug.Log("Game: " + games[i]); // <- This prints null for each game
}
}
}
public class ServerConnector : MonoBehaviour
{
HttpClient httpClient;
ContentfulClient client;
// Awake is called before Start
void Awake()
{
httpClient = new HttpClient();
client = new ContentfulClient(httpClient, *keys omitted*);
}
public async Task<Episode> GetAllContentFromEpisode(string id)
{
var entry = await client.GetEntry<Episode>(id);
return entry;
}
}
public class QuizGameQuestion : Game
{
public string questionType {get; set;}
public string id {get; set;}
public string question {get; set;}
public string options {get; set;} //Options will be a list contained in a JSON
public string answer {get; set;}
public int points {get; set;}
}