我有以下index.js文件;
var Lob = require('lob')('test_6afa806011ecd05b39535093f7e57757695');
var residence = require('./addresses.json');
console.log(residence.residence.length);
for (i = 0; i < residence.residence.length; i++) {
console.log(residence.residence[i].name);
Lob.addresses.create({
name: 'residence.residence[i].name',
}, function(err, res) {
console.log(err, res);
});
}
当我
console.log( residence.residence[i].name )
时,将出现相应的响应“ RESIDENT”。但是,我试图在
Lob.addresses.create({
下传递与post请求中的值相同的值,该值无法识别。如何将该值作为“名称:”的值传递到我的键值对中?
最佳答案
似乎由于使用引号而传递了文字字符串'residence.residence [i] .name'。请删除引号:
for (i = 0; i < residence.residence.length; i++) {
console.log(residence.residence[i].name);
Lob.addresses.create({
name: residence.residence[i].name,
}, function(err, res) {
console.log(err, res);
});
}