C#
C#

help

Root Question Message

DiMiaN
DiMiaN3/14/2023
✅ 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);
    }
}

Instead of value "PUKAN" I want the data from string player instead.
DiMiaN
DiMiaN3/14/2023
oh nevermind, solved it
DiMiaN
DiMiaN3/14/2023
Console.WriteLine(dynamicData.toon_guid_by_gateway[Convert.ToString(gateway)][player];
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy