-1

I have following json coming from server

{
 "contactList":[{

      "contactName":"Jhon",
      "address":null,
      "phone":null,
      "contactId":99932

}]

}

now when i am deserializing using JsonConvert.DeserializeObject<Response>(content) i want following output

{
     "contactList":[{

          "contactName":"Jhon",
          "contactId":99932

    }]

    }

i tried following code but its not working

 JsonSerializerSettings jsonSettings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore,
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    };

this is my Contact model

public class Contact 
    {
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public String address { set; get; }

       [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
         public String phone { set; get; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
         public String name { set; get; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
         public String id { set; get; }
  }

model of Response

     [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
 public class Response 
    {
         [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public IList<SignodeMSA.Model.Master.Contact> contactsList { get; }
  }

and i am deserializing after fetching it from server

  Response responseData = await Task.Run(() => JsonConvert.DeserializeObject<Response>(content, jsonSettings));
Hunt
  • 8,215
  • 28
  • 116
  • 256

1 Answers1

0

I think you need manually delete that properties from json string.

Maybe like this : How do I remove all null and empty string values from a json object?

Community
  • 1
  • 1
wikiCan
  • 449
  • 3
  • 14