0

I'm trying to log some items from a JSON object, that I'm getting from an API, to the console using c# with the following code:

using DocumentFormat.OpenXml.Office.CustomUI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net;

    static void GetCoinValues()
    {

        string json = new WebClient().DownloadString("https://api.coinmarketcap.com/v1/ticker/");

        List<Item> items = JsonConvert.DeserializeObject<List<Item>>(json);

        foreach (var item in items)
        {
            Console.WriteLine("ID: " + item.id.ToUpper());
            Console.WriteLine("Name: " + item.name.ToUpper());
            Console.WriteLine("Symbol: " + item.symbol.ToUpper());
            Console.WriteLine("Rank: " + item.rank.ToUpper());
            Console.WriteLine("Price (USD): " + item.price_usd.ToUpper());
            Console.WriteLine("\n");
        }
    }

Wich I got from here: https://stackoverflow.com/a/48104016/11234800

But I keep getting the same error code "CS1061", for all the items I'm trying to print:

Severity Code Description Project File Line Suppression State Error CS1061 'Item' does not contain a definition for 'id' and no accessible extension method 'id' accepting a first argument of type 'Item' could be found (are you missing a using directive or an assembly reference?) ApiTesting C:\Users\raschmitt\source\repos\raschmitt\tranigcsharp\17_10\ApiTesting\ApiTesting\Program.cs 28 Active

What am I doing wrong, and how I can correct it?

Rogerio Schmitt
  • 1,055
  • 1
  • 15
  • 35

0 Answers0