Jaya Prakash

Jaya Prakash

  • 546
  • 2.3k
  • 64.8k

How to map class name with json property?

Feb 19 2024 10:38 AM
{
  "3G/4G": [
    {
      "rs": "15",
      "desc": "Pack validity Active Plan Total data 1 GB Data at high speed* 1 GB",
      "validity": "N/A",
      "last_update": "01-01-1970"
    }
  ],
  "2G": [
    {
      "rs": "26",
      "desc": "JioPhone Pack validity 28 Days Total data 2 GB Data at high speed* 2 GB Voice NA SMS NA",
      "validity": "28 days"
    }
  ]
}

here im getting my response like this when i did deserialization im unable to map this list to respected entity class
 

public class Response
    {
        public int status { get; set; }
        public Rdata rdata { get; set; }
    }
    public class Rdata
    {

        [JsonProperty(PropertyName="3G/4G")]
        public List<_3G4G> _3G4G { get; set; }
       [JsonProperty(PropertyName="2G")]
        public List<_2G> _2G { get; set; }
        public List<Romaing> Romaing { get; set; }
    }

  public class _3G4G
    {
                public decimal rs { get; set; }
                public string desc { get; set; }
                public string validity { get; set; }
                public string last_update { get; set; }
    }
            
  public class _2G
    {
                public decimal rs { get; set; }
                public string desc { get; set; }
                public string validity { get; set; }
                public string last_update { get; set; }
    }
        

this is what i tried. I just want to map the response 3G/4G with my class i know we cant keep class name with numbers but im unable to map properties for 2g and 3g/4g Pls help me


Answers (5)