postman - Postman 测试 - 使用变量解析 JSON 请求时出错
问题描述
“pulic_token”变量已准备好定义。
我的预请求测试如下所示:
pm.test("Public token is correct", () => {
const req = JSON.parse(request.data);
pm.expect(req.public_token).to.be.a("string");
});
错误:
JSONError: Unexpected token 'p' at 4:21 "public_token": {{public_token}} ^
解决方案
The error is from
JSON.parse(request.data)
The error says :
JSONError: Unexpected token 'p' at 4:21 "public_token": {{public_token}} ^
THis indicate that public_token variable was not resolved , if it was resolved the error would be something like (assuming value of variable is pet)
JSONError: Unexpected token 'p' at 4:21 "public_token": pet ^
So check whether correct environment or variable is defined
Output:
when environment not selected
when environment was selected
推荐阅读
- bash - 从bash中的另一个函数中调用一个函数
- spring - 带有@ModelAttribute 的变量是否从请求参数中填充?
- html - 如何获取 HTML 和 CSS 中的所有链接
- javascript - 根据您单击的位置使 div 上的颜色发生变化
- css - 性能更好的 CSS 过滤器替代方案:blur()
- asp.net - 是否可以在 IIS 上执行功能以在点击 URL 之前进行身份验证?
- ios - iOS 添加了多个 CALayer,但只应用了一个
- json - 在 SharePoint 列中格式化 > 居中对齐文本的 JSON 语法是什么
- excel - DB2 SQL:从 EXCEL 复制 IF-ELSE 语句并使用 DB2 SQL 中的 CASE 语句
- unity3d - 重新加载场景后保留对象