【发布时间】:2020-08-05 10:49:14
【问题描述】:
在 Postman 桌面中,我正在尝试渲染 Bing 图像搜索返回的图像。 (查询本身有效。)
我收到了来自 Bing API 查询的以下响应,在桌面 Postman 中格式化为 JSON:
{
"_type": "Images",
"instrumentation": {
"_type": "ResponseInstrumentation"
},
"readLink": "https://arama.cognitiveservices.azure.com/api/v7/images/search?q=jfk",
"webSearchUrl": "https://www.bing.com/images/search?q=jfk&FORM=OIIARP",
"queryContext": {
"originalQuery": "jfk",
"alterationDisplayQuery": "jfk",
"alterationOverrideQuery": "+jfk",
"alterationMethod": "AM_JustChangeIt",
"alterationType": "CombinedAlterations"
},
"totalEstimatedMatches": 910,
"nextOffset": 1,
"currentOffset": 0,
"value": [
{
"webSearchUrl": "https://www.bing.com/images/search?view=detailv2&FORM=OIIRPO&q=jfk&id=23716A341D61409DE7D5D19724937DD5340BBB06&simid=608036166471451494",
"name": "Reactions to the assassination of John F. Kennedy - Wikipedia",
"thumbnailUrl": "https://tse1.mm.bing.net/th?id=OIP.9dNMVRmk1a3edFYrwzcFeQHaIi&pid=Api",
"isFamilyFriendly": true,
"contentUrl": "https://upload.wikimedia.org/wikipedia/commons/7/70/Jfk2.jpg",
}
]
}
在 Tests 选项卡中,我有以下脚本:
var template = `<img src="{{res.value[0].contentUrl}}">`;
pm.visualizer.set(template, {
res: pm.response.json()
});
这会导致 Visualizer 面板中显示以下错误:
第 1 行解析错误:
我已经使用 w3schools TryIt 在线小提琴单独测试了参考 res.value[0].contentUrl,我知道它可以正常工作并正确生成有问题的 URL。
我在这里做错了什么,如果是你,你会如何调试它?谢谢。
【问题讨论】:
标签: postman handlebars.js