我有一个用botkit构建的机器人,并使用Zendesk api来提取信息。
我有一个功能,要求用户提供搜索词,并且机器人会搜索有关该搜索词的相关信息。它从Zendesk API中提取信息并输出答案。
我无法理解在访问对象的值时,某些值可以输出而某些值不能输出。
例如,如果用户提交了“jim'作为搜索词。我可以通过这样做来获取相关信息:ticket [0] .id + tickets [0] .priority + tickets [0] .subject + tickets [0] .description。
当我做这样的事情时: 门票[4] - 我得到了未定义的值。
我尝试做的完整代码是:
controller.hears(['SEARCH TICKET',/search ticket/gi, /^.{0,}jirabot.
{0,}$/],
['direct_message','direct_mention','mention','ambient'],function(bot,message)
{
// start a conversation to handle this response.
bot.startConversation(message,function(err,convo) {
convo.ask('What are you looking for?',function(response,convo) {
zendesk.search.list('query='+response.text+'&sort_by=priority&sort_order=desc').then(function(tickets){
console.log(tickets);
bot.reply(message, 'The Ticket ID Number: ' + tickets[3] + tickets[0].id + '\n The Ticket Priority: ' + tickets[0].priority + '\n The Ticket Subject: ' + tickets[0].subject + '\n The Ticket Description: \n'+ tickets[0].description + '\n');
convo.next();
}
});
});
});
});
这是JSON的样子:
{
"results": [(in here is the information like ticket subject, priority, id,
etc.],
"facets": null,
"next_page": null,
"previous_page": null,
"count": 2
}
如何获取计数值?当我做票时我得到了不确定[4]。
答案 0 :(得分:0)
To access the properties of the JSON you've shown, you wouldn't use index values like 0,1,2,3. Instead you'd write ticket["results"]
, ticket["count"]
, ticket["<PropNameHere>"]