如何将复杂数组发布到mvc c#api

问题描述 投票:0回答:2

我正在尝试发布一个数组,其中一个成员是字符串数组,我对该数组进行了字符串化,这是它看起来是字符串化的滚刀:

[{"id":"201669887","name":"אורה","Sunday":"1","Monday":"1","Tuesday":"1","Wednesday":"0","Thursday":"1","Friday":"1","Sunday1":"1","Monday1":"1","Tuesday1":"1","Wednesday1":"0","Thursday1":"1","Friday1":"0","totalWorkHour":9,"th":["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""],"year":" ","schoolName":null,"schoolNumber":null},{"id":"201669887","name":"חנה","Sunday":"1","Monday":"1","Tuesday":"1","Wednesday":"0","Thursday":"1","Friday":"1","Sunday1":"1","Monday1":"1","Tuesday1":"1","Wednesday1":"0","Thursday1":"1","Friday1":"0","totalWorkHour":9,"th":["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""] 

我在Mvc中有一个模型:

public class teachersExcelDataModel
    {

  .....
    public int Thursday1 { get; set; }
    public int Friday1 { get; set; }
    public int totalWorkHour { get; set; }

     public List<string> th { get; set; }

     public string schoolName { get; set; }
    public int schoolNumber { get; set; }
    public string month { get; set; }
    public string year { get; set; }

        public teachersExcelDataModel()
        {
            th = new List<string>();
        }

    }

这是我发送的方式:

this.http.post(this.accessPointUrl3, JSON.stringify(this.sendData), { headers: this.headers }).subscribe(
  noteRecord => {
    if (noteRecord)
      this.a = true;
  }
);

这是我的方法:

 public void PostExportExcel([FromBody]List<teachersExcelDataModel>json)

但是它为空,如果我将其作为对象[],那就可以了,我在哪里错?

c# asp.net-mvc typescript api
2个回答
0
投票

基于我从问题中看到的内容,json格式不正确。也缺少“}”和“]”。


0
投票
  1. 您的示例JSON字符串格式不正确。
  2. 固定了json的格式后,您会看到您正试图将“ schoolNumber”字段解析为整数,在您的情况下为“ null”,我猜内部会引发异常-您的原因问题。
© www.soinside.com 2019 - 2024. All rights reserved.