嗨,我正在尝试使用节点js进行API调用,当我尝试在JSON中使用deployerID变量而不是获取测试脚本时,它实际上是在打印“ deployerID”,因此无法让我完成请求。
var deployerID = "test-script";
unirest.put(permURL)
.headers({
'Content-Type':'application/vnd.org.jfrog.artifactory.security.PermissionTarget+json',
'X-JFrog-Art-Api' : api,
sendImmediately: true
}).send({
"name": PermTargetName,
"includesPattern": include,
"excludesPattern": "",
"repositories": [ "test-xyz" ],
"principals": {
"users" : {
deployerID : ["r","w","n"]
}
}
})
有人可以告诉我如何传递变量deployerID的值而不是“ deployerID”的值
最佳答案
在JSON中用方括号将要使用的变量括起来。然后,应将其解析为变量。deployerID : ["r","w","n"]
至[deployerID]: ["r","w","n"]
根据jfriend00的评论-这是ES6语法,因此需要node.js的最新版本(v5