C# json数组解析错误,应用程序在未读取整个请求正文的情况下完成

C# json数组解析错误,应用程序在未读取整个请求正文的情况下完成,c#,json,asp.net-core,C#,Json,Asp.net Core,我在这个问题上被困了4个多小时。我的json看起来不错,至少对jsonLint来说是这样,下面是一个例子: [{ "cnpj": "1", "notasPorConsulta": "1", "partirDe": "1" }, { "cnpj": "2", "notasPorConsulta": "2", "partirDe": "2" }] 或 下面是我如何使用javascript发布的 (async () => { co

我在这个问题上被困了4个多小时。我的json看起来不错,至少对jsonLint来说是这样,下面是一个例子:

[{
    "cnpj": "1",
    "notasPorConsulta": "1",
    "partirDe": "1"
}, {
    "cnpj": "2",
    "notasPorConsulta": "2",
    "partirDe": "2"
}]

下面是我如何使用javascript发布的

(async () => {
        console.log(NovoRastreio);
        const fetchResp = await fetch('api/values/NovoRastreio', {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: NovoRastreio
        })
        .then();
            .then(res => console.log(res.json()));
    })();
我也尝试了不使用async/await。没有成功

首先,我创建了一个基本模型,然后使用QuickType生成了另一个模型

public partial class NovoRastreio
    {
        [JsonProperty("NovoRastreio")]
        public List<NovoRastreioElement> Rastreios { get; set; }
    }

    public partial class NovoRastreioElement
    {
        [JsonProperty("cnpj")]
        public string Cnpj { get; set; }

        [JsonProperty("notasPorConsulta")]
        [JsonConverter(typeof(ParseStringConverter))]
        public long NotasPorConsulta { get; set; }

        [JsonProperty("partirDe")]
        [JsonConverter(typeof(ParseStringConverter))]
        public long PartirDe { get; set; }
    }

不,我每次都会从标题中得到错误,即使我尝试使用postman,而且,我在同一个API中有多个其他帖子,效果很好,不同的是另一个只发布一个JSON对象,而不是多个对象的列表/数组。

好的,您声明了
[JsonProperty(“NovoRastreio”)]
在您的
类NovoRastreio
中,但在您的json中没有具有此名称的字段。 尝试发送如下内容:

{
  "NovoRastreio":
    [{
        "cnpj": "1",
        "notasPorConsulta": "1",
        "partirDe": "1"
    }, {
        "cnpj": "2",
        "notasPorConsulta": "2",
        "partirDe": "2"
    }]
}

谢谢,我也试过这样做,我编辑了我的问题。@GAltelino你的
ParseStringConverter
是什么?为什么您的型号是部分的?删除[JsonConverter(typeof(ParseStringConverter))],然后重试。我和邮递员一起工作了。@GAltelino帮不了你,因为它应该工作。尝试创建新的WebAPI项目,手动创建模型并使用Postman。我做到了,这对我很有效。
[HttpGet("NovoRastreio")]
        public void NovoRastreioPorCnpj([FromBody]NovoRastreio rastreios )
        {
            System.Console.WriteLine(rastreios);
        }
{
  "NovoRastreio":
    [{
        "cnpj": "1",
        "notasPorConsulta": "1",
        "partirDe": "1"
    }, {
        "cnpj": "2",
        "notasPorConsulta": "2",
        "partirDe": "2"
    }]
}