如果您打开this链接,您将获得JSON数据。当我尝试遍历它时,我可以完美地从最初的节点获取数据,即:"SearchResultCount" & "SearchResultCountAll"
甚至第二个对象内的两个元素。但是当我尝试从"JobCategory" & "CareerLevel" & "UserArea" descriptions
对象中获取数据时会出现问题,我正在以这种方式遍历它们:
//Loaded through Casper JS
var doc = JSON.parse(this.getPageContent());
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.PositionTitle)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.PositionURI)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.JobCategory[0].Name)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.CareerLevel[0].Name)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.ParentOrganizationName)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.UserArea.TextJobDescription +
doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.UserArea.TextRequirementDescription)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.PublicationStartDate)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.OrganizationName)

显示前两个数据,但其余数据显示为
undefined is not an object
我不知道这是什么问题!
答案 0 :(得分:0)
对我来说很好。 (运行下面的代码段)
const url = 'https://telekom.jobs/globaljobboard_api/v3/search/%7B%22JobadID%22%3A%22%22%2C%22LanguageCode%22%3A%222%22%2C%22SearchParamters%22%3A%7B%22FirstItem%22%3A1%2C%22CountItem%22%3A1000%2C%22.json';
fetch(url).then(data => data.json()).then(doc => {
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.PositionTitle)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.PositionURI)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.JobCategory[0].Name)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.CareerLevel[0].Name)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.ParentOrganizationName)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.UserArea.TextJobDescription +
doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.UserArea.TextRequirementDescription)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.PublicationStartDate)
console.log(doc.SearchResult.SearchResultItems[0].MatchedObjectDescriptor.OrganizationName)
});

您的问题可能出在this.getPageContent()中。