Я использую запрос узла для доступа к данным API.Теперь, когда я использую следующий код для доступа к телу, я получаю следующий ответ.
app.post("/", function(req, res){
//var series = req.body.series;
var circuits = req.body.Circuits;
var url = req.body.url
request("http://ergast.com/api/f1/circuits/" + circuits + ".json", function(error, response, body){
console.log(body);
res.write("<p>Here is the information about the circuit " + circuits + " in the " + url + " is about the circuit </p>")
});
})
, и я получаю следующий ответ от API.
{
"MRData": {
"xmlns": "http://ergast.com/mrd/1.4",
"series": "f1",
"url": "http://ergast.com/api/f1/circuits/brands_hatch.json",
"limit": "30",
"offset": "0",
"total": "1",
"CircuitTable": {
"circuitId": "brands_hatch",
"Circuits": [
{
"circuitId": "brands_hatch",
"url": "http://en.wikipedia.org/wiki/Brands_Hatch",
"circuitName": "Brands Hatch",
"Location": {
"lat": "51.3569",
"long": "0.263056",
"locality": "Kent",
"country": "UK"
}
}
]
}
}
}
Теперь вопрос в том, чтоМне нужно получить доступ к свойствам.Как, например, URL дает мне ошибку undefined в теге абзаца.Любая помощь будет оценена.