Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. [Solved]How i deserialize a specific JSON with Newtonsoft

[Solved]How i deserialize a specific JSON with Newtonsoft

Scheduled Pinned Locked Moved C#
collaborationjson
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kapparina
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • K Kapparina

      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

      J Offline
      J Offline
      josda1000
      wrote on last edited by
      #2

      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 the object field, so either specify a class or a value type.

      Josh Davis
      This is what plays in my head when I finish projects.

      K 1 Reply Last reply
      0
      • J josda1000

        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 the object field, so either specify a class or a value type.

        Josh Davis
        This is what plays in my head when I finish projects.

        K Offline
        K Offline
        Kapparina
        wrote on last edited by
        #3

        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:

        J 1 Reply Last reply
        0
        • K Kapparina

          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:

          J Offline
          J Offline
          josda1000
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups