내 페이지에 두 개의 JSON이 있습니다. 두 번째 페이지에는 특정 객체 'articleSection'이 들어 있으며 첫 번째 페이지에는 없습니다. JSON이 발견 될 때까지 모든 스크립트를 반복하고, 'articleSection이 있는지'를 확인하기 위해 각 JSON을 반복합니다. 그것이 존재한다면, 나는 'articleSection'의 가치를 돌려주고 싶다.페이지의 모든 JSON을 반복하고 특정 ID를 찾으십시오.
나는 지금까지이 모든 것을 얻었지만 반환 값은 항상 정의되지 않았습니다.
:
function getJSON() {
var JSONS = document.getElementsByTagName("Script")
for (i=0; i<JSONS.length;i++){
if (JSONS[i].getAttribute("type") == "application/ld+json"){
var jsonParsed = JSON.parse(JSONS[i].innerText);
if (jsonParsed.articleSection != null && jsonParsed.articleSection != ""){
return jsonParsed.articleSection;
}
}
}
}
나의 생각은 내가 제대로 만에 refrence에 대한 초기 if JSONS[i].getAttribute("type") == "application/ld+json
JSON에서 발견되는 첫 번째 통해 오히려 JSON 스크립트의 각 통해 반복,하지만 오전입니다 JSON ONE :
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Organization",
}
</script>
JSON 2 :
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Article",
"keywords": "",
"author": {
"@type": "Person",
"name": "Staff"
},
"articleSection": "Christmas, Festivals, Events, Life, Arts"
}
'내 page' 두 JSON이가 내 page' 3 HTML이'말처럼 - 그것은 이해가되지 않습니다. – ProEvilz
당신의 아들은 어디 있습니까? – Joschi
방금 추가 된 – SFro