如何从 UrlFetchApp/waiting 函数中减慢读取输出,直到得到 url(Google Apps 脚本)的响应
How to slow read output from UrlFetchApp/ waiting function till get respond from url (Google Apps Script)
var api_url = 'dns.google/resolve?name=site.com';
var response = UrlFetchApp.fetch(api_url);
var responseText = response.getContentText();
return {text : responseText};
当我有运行这个时,输出会得到这个
{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "site.com.","type": 1}],"Answer":[ {"name": "site.com.","type": 1,"TTL": 299,"data": "204.74.99.100"}],"Comment": "Response from 204.13.250.39."}
我需要这个输出,通过解析。
[ {"name": "site.com."
"type": 1
"TTL": 299
"data": "204.74.99.100"
} ]
但在实际情况下,它的注释得到 output.even 虽然 运行 通过 bash 脚本会得到响应,
$]curl -s https://dns.google/resolve?name=site.com
{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "site.com.","type": 1}],"Answer":[ {"name": "site.com.","type": 1,"TTL": 188,"data": "204.74.99.100"}]}
这里可以做什么,有人可以建议我对 Javasript 和使用 JSON
解析数据了解较少吗
function getDatta() {
const json = '{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "site.com.","type": 1}],"Answer":[ {"name": "site.com.","type": 1,"TTL": 299,"data": "204.74.99.100"}],"Comment": "Response from 204.13.250.39."}';
const obj = JSON.parse(json);
Logger.log(JSON.stringify(obj.Answer));
}
Execution log
5:07:41 PM Notice Execution started
5:07:41 PM Info [{"name":"site.com.","type":1,"TTL":299,"data":"204.74.99.100"}]
5:07:42 PM Notice Execution completed
var api_url = 'dns.google/resolve?name=site.com';
var response = UrlFetchApp.fetch(api_url);
var responseText = response.getContentText();
return {text : responseText};
当我有运行这个时,输出会得到这个
{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "site.com.","type": 1}],"Answer":[ {"name": "site.com.","type": 1,"TTL": 299,"data": "204.74.99.100"}],"Comment": "Response from 204.13.250.39."}
我需要这个输出,通过解析。
[ {"name": "site.com."
"type": 1
"TTL": 299
"data": "204.74.99.100"
} ]
但在实际情况下,它的注释得到 output.even 虽然 运行 通过 bash 脚本会得到响应,
$]curl -s https://dns.google/resolve?name=site.com
{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "site.com.","type": 1}],"Answer":[ {"name": "site.com.","type": 1,"TTL": 188,"data": "204.74.99.100"}]}
这里可以做什么,有人可以建议我对 Javasript 和使用 JSON
解析数据了解较少吗function getDatta() {
const json = '{"Status": 0,"TC": false,"RD": true,"RA": true,"AD": false,"CD": false,"Question":[ {"name": "site.com.","type": 1}],"Answer":[ {"name": "site.com.","type": 1,"TTL": 299,"data": "204.74.99.100"}],"Comment": "Response from 204.13.250.39."}';
const obj = JSON.parse(json);
Logger.log(JSON.stringify(obj.Answer));
}
Execution log
5:07:41 PM Notice Execution started
5:07:41 PM Info [{"name":"site.com.","type":1,"TTL":299,"data":"204.74.99.100"}]
5:07:42 PM Notice Execution completed