I want to loop through times, but times is undefined when debugging.
router.post('/something', function (req, res) {
var times = req.body.times;
for (i = 0; i < times.length; i++) {
// do something
}
}
Here is what body.times looks like when debugging:
{"duration":3600,"startTime":540,"weekDay":0},{"duration":3600,"startTime":600,"weekDay":0},{"duration":3600,"startTime":660,"weekDay":0},{"duration":3600,"startTime":1080,"weekDay":6}:""
Here's a screenshot of what it looks like in VSCode debugging. Replace spans with times. (I just changed it to times on this question to be more clear.)

Here is the swift code:
var jsonArray: [[String: Any]] = [/*The array*/]
let json: [String: Any] = ["times": jsonArray]
guard let body = (try? JSONSerialization.data(withJSONObject: json,
options: []))
else {
return nil
}
Here is how I configure express:
var app = express();
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
app.use(bodyParser.json({ type: 'application/*+json' }))
app.use(bodyParser.json({ type: 'application/json' }))
app.use(bodyParser.json({ type: 'application/x-www-form-urlencoded'}))
Output of json:
(lldb) po print(json)
["spans": [["weekDay": 0, "duration": 3600.0, "startTime": 540], ["weekDay": 0, "duration": 3600.0, "startTime": 600]]]

body.timesreally an array? it looks like you've got trailing:""and missing[]jsonArray