[Solved]How i deserialize a specific JSON with Newtonsoft
-
Hello , I have this Json :
[
{
"Created_Datetime": "",
"Id": ,
"Last_Login_Datetime": "",
"Leaves": 5,
"Level": 102,
"Losses": 552,
"MasteryLevel": 39,
"Name": "",
"Personal_Status_Message": "",
"Platform": "",
"RankedConquest": {
"Leaves": 0,
"Losses": 21,
"Name": "Conquest",
"Points": 70,
"PrevRank": 0,
"Rank": 0,
"Rank_Stat_Conquest": null,
"Rank_Stat_Duel": null,
"Rank_Stat_Joust": null,
"Season": 2,
"Tier": 15,
"Trend": 0,
"Wins": 14,
"player_id": null,
"ret_msg": null
},
"Region": "Europe",
"TeamId": 0,
"Team_Name": "",
"Tier_Conquest": 15,
"Total_Achievements": 51,
"Total_Worshippers": 91811438,
"Wins": 604,
"ret_msg": null
}
]And I can't deserialize it entirely with Newtonsoft What I have tried:
var player1 = JsonConvert.DeserializeObject>(Json);
But all the information in "RankedConquest" are null I have a class named Player :
public class Player { public string Account\_Level { get; set; } public string ChampionName { get; set; } ... etc ... public IList m\_championslist; public class RankedConquest { public int Leaves { get; set; } public int Losses { get; set; } public string Name { get; set; } public int Points { get; set; } public int PrevRank { get; set; } public int Rank { get; set; } //Removed public object Rank\_Stat\_Conquest { get; set; } //Removed public object Rank\_Stat\_Duel { get; set; } //Removed public object Rank\_Stat\_Joust { get; set; } public int Season { get; set; } public int Tier { get; set; } public int Trend { get; set; } public int Wins { get; set; } //Removed public object player\_id { get; set; } public string ret\_msg { get; set; }// Edited } }
}
With wich I can do :
Player player1 = JsonConvert.DeserializeObject(Json.Substring(1, Json.Length - 2));
Same here all the information in "RankedConquest" are null
-
Hello , I have this Json :
[
{
"Created_Datetime": "",
"Id": ,
"Last_Login_Datetime": "",
"Leaves": 5,
"Level": 102,
"Losses": 552,
"MasteryLevel": 39,
"Name": "",
"Personal_Status_Message": "",
"Platform": "",
"RankedConquest": {
"Leaves": 0,
"Losses": 21,
"Name": "Conquest",
"Points": 70,
"PrevRank": 0,
"Rank": 0,
"Rank_Stat_Conquest": null,
"Rank_Stat_Duel": null,
"Rank_Stat_Joust": null,
"Season": 2,
"Tier": 15,
"Trend": 0,
"Wins": 14,
"player_id": null,
"ret_msg": null
},
"Region": "Europe",
"TeamId": 0,
"Team_Name": "",
"Tier_Conquest": 15,
"Total_Achievements": 51,
"Total_Worshippers": 91811438,
"Wins": 604,
"ret_msg": null
}
]And I can't deserialize it entirely with Newtonsoft What I have tried:
var player1 = JsonConvert.DeserializeObject>(Json);
But all the information in "RankedConquest" are null I have a class named Player :
public class Player { public string Account\_Level { get; set; } public string ChampionName { get; set; } ... etc ... public IList m\_championslist; public class RankedConquest { public int Leaves { get; set; } public int Losses { get; set; } public string Name { get; set; } public int Points { get; set; } public int PrevRank { get; set; } public int Rank { get; set; } //Removed public object Rank\_Stat\_Conquest { get; set; } //Removed public object Rank\_Stat\_Duel { get; set; } //Removed public object Rank\_Stat\_Joust { get; set; } public int Season { get; set; } public int Tier { get; set; } public int Trend { get; set; } public int Wins { get; set; } //Removed public object player\_id { get; set; } public string ret\_msg { get; set; }// Edited } }
}
With wich I can do :
Player player1 = JsonConvert.DeserializeObject(Json.Substring(1, Json.Length - 2));
Same here all the information in "RankedConquest" are null
I believe the issue lies in that you have multiple fields in Ranked (formerly RankedConquest) marked as type
object
. I'm pretty sure Newtonsoft doesn't know how to convert from whatever is in the JSON string to theobject
field, so either specify a class or a value type.Josh Davis
This is what plays in my head when I finish projects. -
I believe the issue lies in that you have multiple fields in Ranked (formerly RankedConquest) marked as type
object
. I'm pretty sure Newtonsoft doesn't know how to convert from whatever is in the JSON string to theobject
field, so either specify a class or a value type.Josh Davis
This is what plays in my head when I finish projects.Thank you, I edited my code but all the data in player1.RankedConquest are still 0 or null Edit ------------------------------------------------------------------------------------------ Don't know why but all the code work fine now, thank you :thumbsup:
-
Thank you, I edited my code but all the data in player1.RankedConquest are still 0 or null Edit ------------------------------------------------------------------------------------------ Don't know why but all the code work fine now, thank you :thumbsup:
very odd. if you come up with the reason why, i'd be curious.
Josh Davis
This is what plays in my head when I finish projects.