且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将JSON转换为对象失败-无法将当前JSON对象反序列化为System.Collections.Generic.List

更新时间:2023-01-17 21:51:17

首先,您必须弄清楚API返回的内容.

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

现在,您正在尝试解析jsonToObj Arrays(List<jsonToObj[]>)的List.您必须决定使用API​​现在提供的jsonToObj[]List<jsonToObj>还是简单的jsonToObj:

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

var a = JsonConvert.DeserializeObject<jsonToObj>(richTextBox1.Text);

但是这会引发:

JSON整数918819437284对于Int32而言太大或太小.路径"messages [0] .recipient",第25行,位置33."

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

因此请确保为此使用Long.

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

此外,如果需要以下信息,您可以inDND添加到您的jsonToObj类中:

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

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