I'm sure I am missing something very obvious, and I've read different threads (like this one, this and also this, just to name the last ones) but I still cannot find the answer...
Here are my classes:
using System;
using Newtonsoft.Json;
namespace WebAPIClient
{
public class XWTournament
{
private string name;
[JsonProperty("name")]
public string Name { get => name; set => name = value; }
}
public class Root
{
public XWTournament xwtournam { get => xwtournam; set => xwtournam = value; }
}
}
And here I try to use them:
msg = "{\"tournament\": {\"Name\": \"Worlds 2014 Flight One\"}}";
Root root = JsonConvert.DeserializeObject<Root>(msg) ;
string pippo = root.xwtournam.Name;
But in this case I am receiving a stack overflow error...
What am I missing? How can I read the variables in the string?
Edit: thanks to the useful answers, I have corrected the code in this way
using System;
using Newtonsoft.Json;
namespace WebAPIClient
{
public class XWTournament
{
//I've deleted the private variable
public string Name { get; set; }
}
public class Root
{
[JsonProperty("tournament")]
public XWTournament xwtournam { get; set; }
}
}
{ get; set; }would do exactly the same, and you wouldn't need private fields then.