박지환

Update get data array

Showing 1 changed file with 31 additions and 2 deletions
......@@ -14,10 +14,13 @@ var url =
"http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/" +
operation;
var queryParams = "?" + "solYear" + "=" + "2022";
queryParams += "&" + "solMonth" + "=" + "05";
queryParams += "&" + "solMonth" + "=" + "09";
queryParams += "&" + "ServiceKey" + "=" + SERVEICE_KEY;
let requestUrl = url + queryParams;
var text = "";
var text2 = "";
var dateName = [];
var locdate = [];
app.get("/", function (req, res) {
request.get(requestUrl, (err, res, body) => {
......@@ -36,11 +39,37 @@ app.get("/", function (req, res) {
console.log(res);
text = JSON.stringify(res);
console.log(text);
dateName = [];
var idx = text.indexOf("dateName", 0);
while (idx != -1) {
console.log(idx);
var start = text.indexOf("[", idx) + 2;
var end = text.indexOf("]", idx) - 1;
var tempStr = text.substring(start, end);
console.log(tempStr);
dateName.push(tempStr);
idx = text.indexOf("dateName", idx + 1);
}
console.log(dateName);
locdate = [];
idx = text.indexOf("locdate", 0);
while (idx != -1) {
console.log(idx);
var start = text.indexOf("[", idx) + 2;
var end = text.indexOf("]", idx) - 1;
var tempStr = text.substring(start, end);
console.log(tempStr);
locdate.push(tempStr);
idx = text.indexOf("locdate", idx + 1);
}
console.log(locdate);
text2 = dateName.toString() + "&" + locdate.toString();
});
}
}
});
res.send(text);
// res.send(text);
res.send(text2);
});
const port = 8080;
......