Search code examples
c#jsonjson-deserialization

How to deserialize json body with "0" in parameter


I'm using a API that give me this json as a response, This is json response body :

{
   "meta":{
      "status":200,
      "message":"success"
   },
   "data":{
      "0":{
         "MsgID":"2661689817",
         "Status":"6",
         "SendTime":"2021-10-3114:30:04",
         "DeliverTime":"2021-10-31 14:30:07"
      }
   }
}

My problem is "0":{... in this body.

How can I deserialize this into a Class.

it can't deserialize on "string _0" prop.


Solution

  • try using JsonProperty

    public class Data
    {
        [JsonProperty("0") ]
        public _0 _0 { get; set; }
    }
    
    public class _0
    {
        public string MsgID { get; set; }
        public string Status { get; set; }
        public string SendTime { get; set; }
        public string DeliverTime { get; set; }
    }