I did search but seem like i didnt find any solution for this... This is my sample Json:
{
"WSettings":{
"Message":"\"We are the universe's way of experiencing itself.\"<br/>- Kurzgesagt -",
"universalMessageProcChance":10,
"Hi":{
"altName":"Hi",
"normalState":"hi",
"hState":"hi_h",
"aState":"hi_a",
"background":"bg_owo_r",
"stateLayout":4,
"backgroundLayout":1,
"eventMessage":"Da"
},
"Yu":{
"altName":"Al",
"normalState":"al",
"hState":"al_h",
"aState":"ali_a",
"background":"bg_owo_b",
"stateLayout":4,
"backgroundLayout":1,
"eventMessage":"Da"
}
}
}
This is my classes:
public class WSettings
{
public string Message { get; set; }
public int universalMessageProcChance { get; set; }
[JsonProperty("Hi")]
public StateW Hi { get; set; }
[JsonProperty("Yu")]
public StateW Yu { get; set; }
}
public class StateW
{
public string altName { get; set; }
public string normalState { get; set; }
public string hState { get; set; }
public string aState { get; set; }
public string background { get; set; }
public int stateLayout { get; set; }
public int backgroundLayout { get; set; }
public string eventMessage { get; set; }
}
and this to deserialize:
var w = Newtonsoft.Json.JsonConvert.DeserializeObject<WSettings>(File.ReadAllText(@"json.txt"));
It returns all attributes as null. I honestly dont know what is wrong there so please pardon my ignorant. Any help is appericated :)
"WSettings"is the property of an object. you need that object to deserialize itpublic class Rootobject { public Wsettings WSettings { get; set; }}thenDeserializeObject<Rootobject>