[英]Crawling JSON-LD schema : detailedDescription undefined?
我正在使用Google知识图搜索(kgsearch)api返回架构(schema.org),但某些嵌套元素未被识别为json或缺少某些内容...
url = "https://kgsearch.googleapis.com/v1/entities:search";
request.get(url).query({
key: KEY,
types: "Person",
query:"Taylor Swift", //search expression
limit: 1,
indent: true
}).end(function(err, response){
console.log(response.body.itemListElement.detailedDescription);
});
在Google api文档中,它应返回如下内容:
[{"@type": "ItemList",
"itemListElement": [
{
"@type": "EntitySearchResult",
"result": {
"@id": "kg:/m/0dl567",
"name": "Taylor Swift",
"@type": [
"Thing",
"Person"
],
"description": "Singer-songwriter",
"image": {
"contentUrl": "https://t1.gstatic.com/images?q=tbn:ANd9GcQmVDAhjhWnN2OWys2ZMO3PGAhupp5tN2LwF_BJmiHgi19hf8Ku",
"url": "https://en.wikipedia.org/wiki/Taylor_Swift",
"license": "http://creativecommons.org/licenses/by-sa/2.0"
},
"detailedDescription": {
"articleBody": "Taylor Alison Swift is an American singer-songwriter and actress. Raised in Wyomissing, Pennsylvania, she moved to Nashville, Tennessee, at the age of 14 to pursue a career in country music. ",
"url": "http://en.wikipedia.org/wiki/Taylor_Swift",
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
},
"url": "http://taylorswift.com/"
},
"resultScore": 896.576599
}]
但是这是node.js返回的内容:
[ { '@type': 'EntitySearchResult',
result:
{ '@id': 'kg:/m/0576bq',
name: '2005–06 NHL season',
'@type': [Object],
description: 'Sports League Season',
detailedDescription: [Object] },
resultScore: 10.426484 } ]
为什么detailDescription字段不以字符串形式返回? 当我尝试直接访问它时,它返回“未定义”。
谢谢!
它返回一个不是字符串的JSON对象,因此您需要JSON.stringify方法以字符串格式打印嵌套的对象。 console.log(JSON.stringify(response.body.itemListElement.detailedDescription, null, 4));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.