0

I'm trying to post an array tat one of it's members (th) is an array of strings, I stringify the array, here is hob it looks stringified:

[{"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":["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""] 

I have a model in 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>();
        }

    }

here is how i send it:

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

and here is how I get it:

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

but it comes null, if i get it as object[], it;s okay, where am i wrong?

2
  • remove JSON.stringify Commented Dec 9, 2019 at 8:56
  • so the count is 0 instead of null, Commented Dec 9, 2019 at 9:24

2 Answers 2

1
  1. Your example JSON string is not in correct format.
  2. After fixing the format of the json, you will see that you are trying to parse schoolNumber field to integer, which in your case is null and I guess internally the framework throws exception.
  3. Trying to parse the data to object[] does not require parsing null to integer, so now you know why it works in this case
Sign up to request clarification or add additional context in comments.

Comments

0

the json format is incorrect based on what i can see from the question. missing "}" and "]" too.

2 Comments

so what can i do? how can I stringify it in other way?
this is the entire json: "[{"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},{......(shortened)........,"totalWorkHour":9,"th":["","","","","","","","","","","","","","","","","","","","","","",,"","","","","","",""],"year":" ","schoolName":null,"schoolNumber":null}]"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.