A
A
armadillo-cld2020-07-07 16:54:45
C++ / C#
armadillo-cld, 2020-07-07 16:54:45

How to get value from array to json?

Hello everyone
I saw a bunch of answers, but I tried everything and I can not get the value in any way !!!
There is a taco class:

public bool StartMessage { get; set; } = false;
        public List<string> users = new List<string>();
        public List<string> keys = new List<string>();
        public List<string> blacklist = new List<string>();


        public static void Save(Settings[] settings) => File.WriteAllText("settings.json", JsonConvert.SerializeObject(settings));

I put values ​​in it and save:
List<string> key = Console.ReadLine().Split(' ').ToList();
                    Settings[] settings = new Settings[]
                    {
                        new Settings
                        {
                            keys = key
                        }
                    };
                    Settings.Save(settings);

Everything is saved normally, but how can I load / read these values ​​now?
I have a particular difficulty with List keys.
Help, please! Lost so much time because of this!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
armadillo-cld, 2020-07-07
@armadillo-cld

Decided!

var des = JsonConvert.DeserializeObject<List<Settings>>(File.ReadAllText("settings.json"));
            foreach(string i in des[0].keys)
            {
                Console.WriteLine(i);
            }

Y
yuopi, 2020-07-07
@yuopi

I wrote in the previous question how to do it.
What for 3 sheets if it is possible to use one List.
And to fill this sheet, you just need to perform deserialization.
https://docs.microsoft.com/en-us/dotnet/standard/s...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question