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

后端 未结 4 1864
暖寄归人
暖寄归人 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 13:03

    I simulated your problem and made the following changes that worked:

    1. Change the method that deserializes to this:

      var a = JsonConvert.DeserializeObject(richTextBox1.Text);
      

      The result of the JSON you receive is not a List, so it will not work to deserialize to List<>.

    2. The recipient property of the messages class receives values larger than an integer, so it must be transformed into a long like this:

      public long recipient { get; set; }
      

    These changes solve your problem.

提交回复
热议问题