Javascript 如果JSON-LD没有';你没有身份证吗?
我试图访问我收到的eventbrite电子邮件中的内容,但html代码没有与JSON-LD脚本关联的ID。那么,有没有办法继续访问这些数据?如果是,怎么做Javascript 如果JSON-LD没有';你没有身份证吗?,javascript,json,google-apps-script,json-ld,Javascript,Json,Google Apps Script,Json Ld,我试图访问我收到的eventbrite电子邮件中的内容,但html代码没有与JSON-LD脚本关联的ID。那么,有没有办法继续访问这些数据?如果是,怎么做 是否可以将临时id附加到JSON-LD脚本标记,以便我可以访问数据?如果是,如何获取?您可以使用 document.querySelectorAll('script[type="application/ld+json"]'); 或者只是第一个 document.querySelector('script[type="application
是否可以将临时id附加到JSON-LD脚本标记,以便我可以访问数据?如果是,如何获取?您可以使用
document.querySelectorAll('script[type="application/ld+json"]');
或者只是第一个
document.querySelector('script[type="application/ld+json"]');
下面是一个完整的示例:
var jsonld=JSON.parse(document.querySelector('script[type=“application/ld+JSON”]).innerText);
document.getElementById('result').innerText=jsonld.endDate代码>
{
“@context”:”http://schema.org",
“@type”:“事件”,
“名称”:“随机事件”,
“开始日期”:“2013-09-14T21:30”,
“结束日期”:“2013-09-14T21:30”
}
结束日期为:
函数myFunction(){
var todayDate=新日期();
var label=GmailApp.getUserLabelByName(“eventbrite”);
var threads=label.getThreads();
对于(var i=0;itodayDate){
线程[i]。标记未读();
}
)
}
}
欢迎来到堆栈溢出。有关如何创建最小、完整和可验证问题的更多信息。为什么需要ID才能访问它?Unor,当我搜索internet时,所有示例都显示使用ID,因此不确定如何在不使用ID的情况下访问它。Markus,感谢您的建议!但是,当我使用var emailDate=document.querySelectorAll('script[type=“application/ld+json”]”)时,我遇到了一个语法错误;此外,一旦我选择了整个json ld,我就只使用email.Date。endDate访问json ld中的数据?(endDate是我想要访问的参数)我已经更新了答案,包含了一个完整的、可运行的示例
function myFunction() {
var todayDate = new Date();
var label = GmailApp.getUserLabelByName("eventbrite");
var threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
threads[i].getMessages()[i].getBody().forEach(
var jsonld = JSON.parse(document.querySelector('script[type="application/ld+json"]').innerText);
document.getElementById('result').innerText = jsonld.endDate;
if (jsonld.endDate > todayDate){
threads[i].markUnread();
}
)
}
}