✅ How to add variable instead of value in JSON dynamic array?
using Newtonsoft.Json;
using System;
public class ConsoleApp7
{
public static void Main()
{
string json = @"
{
""toon_guid_by_gateway"": {
""10"": {
""Cwt)dewalt"": 4,
""Dewalt1"": 6,
""PUKAN"": 14
},
""11"": {
""Dzergalt"": 8,
""Fotono4kiFTW"": 9,
""kekterrek"": 13
},
""20"": {
""BSL15-Dewalt"": 3,
""Cwt)Dewalt"": 5,
""iRk-Dewalt"": 12
},
""30"": {
""BSL-Dewalt"": 2,
""DewaltTv"": 7,
""IllIlIIIllllll1"": 11
},
""45"": {
""asdas12qsdasdas"": 1,
""gantel'kaFTW"": 10
}
}
}";
int gateway = 10;
string player = "Dewalt1";
dynamic dynamicData = JsonConvert.DeserializeObject<dynamic>(json);
Console.WriteLine(dynamicData.toon_guid_by_gateway[Convert.ToString(gateway)].PUKAN);
}
}
using Newtonsoft.Json;
using System;
public class ConsoleApp7
{
public static void Main()
{
string json = @"
{
""toon_guid_by_gateway"": {
""10"": {
""Cwt)dewalt"": 4,
""Dewalt1"": 6,
""PUKAN"": 14
},
""11"": {
""Dzergalt"": 8,
""Fotono4kiFTW"": 9,
""kekterrek"": 13
},
""20"": {
""BSL15-Dewalt"": 3,
""Cwt)Dewalt"": 5,
""iRk-Dewalt"": 12
},
""30"": {
""BSL-Dewalt"": 2,
""DewaltTv"": 7,
""IllIlIIIllllll1"": 11
},
""45"": {
""asdas12qsdasdas"": 1,
""gantel'kaFTW"": 10
}
}
}";
int gateway = 10;
string player = "Dewalt1";
dynamic dynamicData = JsonConvert.DeserializeObject<dynamic>(json);
Console.WriteLine(dynamicData.toon_guid_by_gateway[Convert.ToString(gateway)].PUKAN);
}
}
1 Reply
oh nevermind, solved it
Console.WriteLine(dynamicData.toon_guid_by_gateway[Convert.ToString(gateway)][player];