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

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)

        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.

2 Answers

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);

Deji Adeyemo
Deji Adeyemo
3,703 Points

The correct lines of code are:

var serializer = new JsonSerializer();

using (var jsonReader = new JsonTextReader(reader))

In both cases, it seems you have additional '()' hence the reason they are highlighted in Red.