I am successfully deserializing Json files using JsonConvert.DeserializeObject() but I am having troubles with a fairly large json file with many structures. The problems is in the Stats subclasses which all have a category and abbreviation that are preceeded with @ and a text attribute preceeded by a #. The values are all comming out null.
Here is the class structure
using System;
using System.Collections.Generic;
using System.Text;
namespace SalaryCapData.ConsumeJson.Models.Daily
{
public class Rootobject
{
public Dailyplayerstats dailyplayerstats { get; set; }
}
public class Dailyplayerstats
{
public string lastUpdatedOn { get; set; }
public Playerstatsentry[] playerstatsentry { get; set; }
}
public class Playerstatsentry
{
public Player player { get; set; }
public Team team { get; set; }
public Stats stats { get; set; }
}
public class Player
{
public string ID { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string JerseyNumber { get; set; }
public string Position { get; set; }
}
public class Team
{
public string ID { get; set; }
public string City { get; set; }
public string Name { get; set; }
public string Abbreviation { get; set; }
}
public class Stats
{
public Atbats AtBats { get; set; }
public Runs Runs { get; set; }
public Hits Hits { get; set; }
public Secondbasehits SecondBaseHits { get; set; }
public Thirdbasehits ThirdBaseHits { get; set; }
public Homeruns Homeruns { get; set; }
public Earnedruns EarnedRuns { get; set; }
public Unearnedruns UnearnedRuns { get; set; }
.....
public class Atbats
{
public string category { get; set; }
public string abbreviation { get; set; }
public string #text { get; set; }
}
public class Runs
{
public string category { get; set; }
public string abbreviation { get; set; }
public string text { get; set; }
}
public class Hits
{
public string category { get; set; }
public string abbreviation { get; set; }
public string text { get; set; }
}
public class Secondbasehits
{
public string category { get; set; }
public string abbreviation { get; set; }
public string text { get; set; }
}
}
Here is a sample of the json {
"dailyplayerstats": {
"lastUpdatedOn": "2018-02-22 8:10:18 AM",
"playerstatsentry": [
{
"player": {
"ID": "10437",
"LastName": "Abreu",
"FirstName": "Jose",
"JerseyNumber": "79",
"Position": "1B"
},
"team": {
"ID": "119",
"City": "Chicago",
"Name": "White Sox",
"Abbreviation": "CWS"
},
"stats": {
"AtBats": {
"@category": "Batting",
"@abbreviation": "AB",
"#text": "5"
},
"Runs": {
"@category": "Batting",
"@abbreviation": "R",
"#text": "1"
},
"Hits": {
"@category": "Batting",
"@abbreviation": "H",
"#text": "2"
},
yadda, yadda, yadda.
Not sure if it the reason why the 'text' attribute is coimming back null but notice the '#'? Any ideas?