© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
5 replies
Cvfe Cvt ᵖᵘʳʳ

Error with creating JSON object.

I am trying to deserialize a JSON file. I created the file myself. I am getting this error when I try to deserialize it. I am able to read the file as normal and output its contents, but when I try to create an object from it, it errors out. There are no "/" in the file.

This is my call. It errors out on the second line.
string json = "moves.json"; //Actual filepath is hardcoded
var moves = JsonSerializer.Deserialize<List<Moves>>(json);
string json = "moves.json"; //Actual filepath is hardcoded
var moves = JsonSerializer.Deserialize<List<Moves>>(json);

This is the object class.
using System;
namespace ok
{
    public class Moves
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public int Attack { get; set; }
        public int Accuracy { get; set; }
    }
}
using System;
namespace ok
{
    public class Moves
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public int Attack { get; set; }
        public int Accuracy { get; set; }
    }
}

This is an example of my JSON.
{
  "Moves": [
    {
      "Name": "Leech Life",
      "Type": "BUG",
      "Attack": 15,
      "Accuracy": 100
    },
    {
      "Name": "Pin Missile",
      "Type": "BUG",
      "Attack": 15,
      "Accuracy": 85
    }
  ]
}
{
  "Moves": [
    {
      "Name": "Leech Life",
      "Type": "BUG",
      "Attack": 15,
      "Accuracy": 100
    },
    {
      "Name": "Pin Missile",
      "Type": "BUG",
      "Attack": 15,
      "Accuracy": 85
    }
  ]
}
Screen_Shot_2023-03-26_at_10.19.52_AM.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Deserialization of json object
C#CC# / help
3y ago
✅ filter in json object?
C#CC# / help
4y ago