Converting JSON to Object fails - Cannot deserialize the current JSON object into System.Collections.Generic.List

后端 未结 4 1860
暖寄归人
暖寄归人 2021-01-29 12:48

I\'m using the API of www.textlocal.in, which returns a JSON formatted object.

JSON

{  
   \"warnings\":[  
      {  
         \"messag         


        
4条回答
  •  执念已碎
    2021-01-29 12:57

    Based on string you class structure should be like this :

    public class Warning
    {
        public string message { get; set; }
        public string numbers { get; set; }
    }
    
    public class Message
    {
        public int num_parts { get; set; }
        public string sender { get; set; }
        public string content { get; set; }
    }
    
    public class Message2
    {
        public string id { get; set; }
        public long recipient { get; set; }
    }
    
    public class RootObject
    {
        public List warnings { get; set; }
        public int balance { get; set; }
        public int batch_id { get; set; }
        public int cost { get; set; }
        public int num_messages { get; set; }
        public Message message { get; set; }
        public string receipt_url { get; set; }
        public string custom { get; set; }
        public List inDND { get; set; }
        public List messages { get; set; }
        public string status { get; set; }
    }
    

    It looks like your class structure is not proper, Make use of visual studio and generate C# class from json string and then using that generated class try to deserialize class.

    Read : Visual Studio Generate Class From JSON or XML

提交回复
热议问题