How to create C# class from json null object

I am calling API and get this response from the API.

{
    "StringValue": "Hi Developers",
    "TestMessage": {
        "": [
            "Enjoy Coding."
        ]
    }
}

This is how I tried to make my C# class.

public class MyClass
{
  public string StringValue{ get; set; }
  public TestMessage MessageTest { get; set; }
}
public class TestMessage 
{
  [JsonProperty("")]
  public IList<string> APIResponse{ get; set; }
  //public IList<string> { get; set; }//Also try this but it gives me compilation error
}

but It didn't work how can I get this to work?

2 answers

  • answered 2018-07-11 05:40 Steven Mayer

    The array is incorrect. Try "TestMessage": ["Enjoying Coding.", "Something else"]. You're creating an empty element so it's confusing it. For your object, it's named something different as well. MessageTest should be TestMessage. Lastly, for your actual IList<string>,

    try public IList<string> Messages {get;set;}

  • answered 2018-07-11 05:59 Pradip Meghapra

    can u try this

    public class MyClass
        {
          public string StringValue{ get; set; }
          public TestMessage MessageTest { get; set; }
        }
        public class TestMessage 
        {
          [JsonProperty("")]
          public string[] APIResponse{ get; set; }
        }