UrlFetch를 사용하여 Googe 스크립트에서 데이터를 가져옵니다.
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
Logger.log(typeof(response))
이것은 로깅입니다.
[["Name","email","2016-12-31T00:00:00.000Z","Sim",548]]
object
응답은 배열처럼 보이지만 객체입니다. 배열을 반복 할 수 있어야하는데이 데이터를 대신 배열로 변환하려면 어떻게해야합니까?
쿼리에서 반환되는 콘텐츠 유형에 따라 다릅니다. 예를 들어 JSON이라고 가정합니다.
function myFunction() {
var url = "http://headers.jsontest.com/";
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
try {
// Regular expression for JSON content-type
var jsr = new RegExp(/application\/json/);
var cnt = response.getAllHeaders()["Content-Type"];
// Check if response is JSON
if (jsr.exec(cnt)) {
// Parse response content
var js = JSON.parse( response.getContentText() );
Logger.log(js);
for (var i in js) {
var t = {}; t[i] = js[i];
Logger.log( t );
}
}
} catch(e) {
Logger.log(e)
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다