-1

hi im trying to download data from api and then try some linq on it but i cant even display it normaly. dynamic type works propelly but i cant use linq with it

im using this api http://api.nbp.pl/api/exchangerates/tables/a/?format=json

my class in c#

        public class Rootobject
        {
            public Class1[] Property1 { get; set; }
        }

        public class Class1
        {
            public string table { get; set; }
            public string no { get; set; }
            public string effectiveDate { get; set; }
            public Rate[] rates { get; set; }
        }

        public class Rate
        {
            public string currency { get; set; }
            public string code { get; set; }
            public float mid { get; set; }
        }

    

the code to deserialize :

 using (WebClient client = new WebClient())
            {
                String text = Encoding.UTF8.GetString(client.DownloadData("http://api.nbp.pl/api/exchangerates/tables/a/?format=json"));
                var Data = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(text);

                Debug.WriteLine(Data);

            }

when i put it in array or list (like this)

var Data = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject[]>(text);

i can only see the class path

Sheep
  • 11
  • 1

1 Answers1

0

To correctly represent json returned by provided link you can use array of Class1, not Rootobject:

var Data = Newtonsoft.Json.JsonConvert.DeserializeObject<Class1[]>(text);
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • its only displaying project.Class1[] how can i display all tables? – Sheep May 15 '21 at 22:17
  • @Sheep look at [this](https://stackoverflow.com/questions/52927/console-writeline-and-generic-list) (or [this](https://stackoverflow.com/a/16265268/2501279)) and optionally [override `ToString`](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-override-the-tostring-method) for your classes, for example. Or just serialize it back and print to console) – Guru Stron May 15 '21 at 22:21