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

后端 未结 4 1846
暖寄归人
暖寄归人 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:15

    First of all you have to figure out what your API returns.

    Right now you're trying to parse a List of jsonToObj Arrays (List). You have to decide whether to use a jsonToObj[] or List or a simple jsonToObj which your API provides now:

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

    But this then throws:

    JSON integer 918819437284 is too large or small for an Int32. Path 'messages[0].recipient', line 25, position 33."

    So make sure you use a Long for that.

    public class messages
    {
        public string id { get; set; }
        public long recipient { get; set; }
    }
    

    Furthermore you can add inDND to your jsonToObj class if you need the info:

    public class jsonToObj
    {
      ...
      public string[] inDND { get; set; }
      ...
    }
    

提交回复
热议问题