1

in my c# action method

public void ProcessArray(string jsonArray){
//code here

}

The jsonArray parameter receives the string object in the following format:

[{\"studentid\":6968,\"enrolled\":false},{\"studentid\":6970,\"enrolled\":true},{\"studentid\":6972,\"enrolled\":false} ]

but how do i convert the above json string array to C# object array?

update: here is the full signature of the action method:

pubic json ProcessData(int id, int deptid, int teachId, string studentEnrollmentsArr, string userNotes){

}

i dont want to put all the above parameters to a model i want to pass them as paramters.

thanks

5
  • 2
    Create a model with those 2 properties (int studentid and bool enrolled) and make the method public ActionResult ProcessArray(IEnumerable<yourModel> jsonArray) { ... Commented Apr 11, 2017 at 2:11
  • @StephenMuecke just for curious is it possible to pass jsonArray as a string then internally convert it to a C# object array? Commented Apr 11, 2017 at 3:56
  • Yes (see the answers in the dupe), but why? The DefaultModelBinder will do it for you (assuming you set the contentType: 'application/json' header. Commented Apr 11, 2017 at 4:07
  • @StephenMuecke thanks Commented Apr 11, 2017 at 4:19
  • @StephenMuecke i think i have given you insufficient informaton the actual signature of the method is pubic json ProcessData(int id, int deptid, int teachId, string studentEnrollmentsArr, string userNotes). i have kept it to short in the original for clarity. as i have updated my OP i don't want to put all these parameters in a model instead i want to keep them separate. reason too many things to edit. So if i want keep them as parameters then how do i convert that json array to C# object array? Commented Apr 11, 2017 at 5:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.