I am struggling with converting a JSON object containing a multidimensional array to my class. Despite trying to deserialize the json object, I have not been successful as the JsonMaclar class object remains null. Any assistance would be greatly appreciated.
Below is the script code;
var allFields = new Array();
allFields.push({
FirstParticipantId: firstParticipantId.val(),
SecondParticipantId: secondParticipantId.val(),
FirstScore: firstScore.val(),
SecondScore: secondScore.val(),
GameCount: gameCount.val(),
GameDuration: gameDuration.val(),
GameTime: gameTime.val(),
Defaulted: defaulted.is(':checked'),
IncludeRating: includeRating.is(':checked'),
ShowInTable: showInTable.is(':checked'),
GameDate: gameDate.val()
});
$("#<%=btnSaveGames.ClientID %>").click(function () {
var jsonText = JSON.stringify({
allGamesArray: allFields
});
$('#<%= hfGames.ClientID %>').val(jsonText);
});
Here is the C# code;
protected void btnSaveGames_Click(object sender, EventArgs e)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
JsonGames tournamentGames = serializer.Deserialize<JsonGames>(hfGames.Value);
}
public class JsonGames {
List<JsonGame> allGamesArray { get; set; }
}
public class JsonGame {
String FirstParticipantId { get; set; }
String SecondParticipantId { get; set; }
String FirstScore { get; set; }
String SecondScore { get; set; }
String GameCount { get; set; }
String GameDuration { get; set; }
String GameTime { get; set; }
String Defaulted { get; set; }
String IncludeRating { get; set; }
String ShowInTable { get; set; }
String GameDate { get; set; }
}