C# C# Streams and Data Processing Serialization Deserializing with Json.NET

Ryan White
Ryan White
30,990 Points

Cannot resolve symbol 'JsonSerializer'

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;


namespace SoccerStats
{
    class Program
    {
        static void Main(string[] args)
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            DirectoryInfo directory = new DirectoryInfo(currentDirectory);

            var fileName = Path.Combine(directory.FullName, "SoccerGameResults.csv");
            var fileContents = ReadSoccerResults(fileName);
            fileName = Path.Combine(directory.FullName, "players.json");
            var players = DeserializePlayers(fileName);

            foreach (var player in players)
            {
                Console.WriteLine(player.second_name);
            }
        }

        public static string ReadFile(string fileName)...

        public static List<GameResult> ReadSoccerResults(string fileName)...

        public static List<Player> DeserializePlayers(string fileName)
        {
            var players = new List<Player>();
            var serializer = new JsonSerializer(highlighted in red) ();
            using (var reader = new StreamReader(fileName))
            using (var jsonReader = new JsonTextReader(highlighted in red)(reader))
            {
                players = serializer.Deserialize<List<Player>>(jsonReader);
            }

            return players;
        }
    }
}

I imported Newtonsoft.Json and Newtonsoft.Json.Schema to try to find reference.

Moderator edited: Markdown added so that code renders properly in the forums.

1 Answer

Karlijn Willems
Karlijn Willems
9,961 Points

var serializer = new JsonSerializer(highlighted in red) (); using (var jsonReader = new JsonTextReader(highlighted in red)(reader))

What is the "highlighted in red" for? The syntax (highlighted in red)(); seems a bit odd to me... I think that should be (some parameter, another parameter);