using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
public static class Debug
public static void Log(string s) => Console.WriteLine(s);
public class BC_PlayerInfo
public string ALeaderboards = "";
public BC_PlayerInfo(JsonData jsonData)
Debug.Log(jsonData.ToJson());
ALeaderboards = (string)jsonData;
private string SafeGet(JsonData jsonData, string key)
returnValue = jsonData[key].ToString();
private readonly List<BC_PlayerInfo> alboards = new List<BC_PlayerInfo>();
public void MisDesafios()
string scriptName = "ListEnrolledLeaderboards";
Dictionary<string, object> scriptData = new Dictionary<string, object>();
successCallbackRS(GetJson(), null);
private void successCallbackRS(string jsonResponse, object cbObject)
var aleaderboardData = JsonMapper.ToObject(jsonResponse)["data"]["response"]["aLeaderboards"];
foreach (JsonData alboard in aleaderboardData) alboards.Add(new BC_PlayerInfo(alboard));
foreach (var alboard in alboards)
string _aLeaderboards = alboard.ALeaderboards;
Debug.Log(_aLeaderboards);
private void failureCallbackRS(int status, int reasonCode, string jsonError, object cbObject)
Debug.Log("Error al mostrar el ListEnrolledLeaderboards: " + jsonError);
public static void Test()
var jsonResponse = GetJson();
Console.WriteLine("Input JSON:");
Console.WriteLine(jsonResponse);
var test = new TestClass();
Assert.IsTrue(test.alboards.Select(b => b.ALeaderboards).SequenceEqual(
Newtonsoft.Json.Linq.JToken.Parse(jsonResponse).SelectTokens("data.response.aLeaderboards[*]").Select(t => t.ToString())));
return @"{""data"":{""response"":{""aLeaderboards"":[""PLAYERS_LEADERBOARD"",""MARCHTESTERSCH01"",""MARCHTESTERSCH02"",""MARCHTESTERSCH03"",""MARCHTESTERSCH04"",""LYPSEPCYC01"",""LYPSEPRUN01"",""LYPOCTRUNEX"",""LYPOCTSKAEX"",""LYP202011HIK"",""LYP202011WALK"",""LYP202011CIC"",""LYP202012SKA"",""LYP2020SOLCHRUN"",""LYP2020SOLCHCYC"",""LYP2020SOLCHSKA"",""LYP2020SOLCHWALK"",""LYPWEBHOOKS""],""aEnrolledLB"":[""LYP202012SKA"",""LYP2020SOLCHRUN"",""LYP2020SOLCHCYC""]},""success"":true},""status"":200}";
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("{0} version: {1}", typeof(LitJson.JsonMapper).Assembly.GetName().Name, typeof(LitJson.JsonMapper).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];
Where is the exception getting thrown? I can't reproduce the exception with the JSON data shown in your question if I remove the call to `_bc.ScriptService.RunScript(scriptName, jsonScriptData, successCallbackRS, failureCallbackRS);` and replace it with your JSON as a string literal then no exception is thrown, see https://dotnetfiddle.net/RumLZc. What is `_bc`? What is `_bc.ScriptService.RunScript()` supposed to do? Is it documented to be able to handle JSON arrays?
That being said, you have a bug in the `BC_PlayerInfo` constructor. `ALeaderboards = SafeGet(jsonData, "aLeaderboards");` should be `ALeaderboards = (string)jsonData;` since the JSON being passed in is an entry in the `"aEnrolledLB"` array.