Javascript TypeError:无法读取未定义的属性“合格”
我有这段1年前的代码,现在需要运行它。 欢迎任何可能的猜测。任何信息都会有帮助,谢谢Javascript TypeError:无法读取未定义的属性“合格”,javascript,typeerror,Javascript,Typeerror,我有这段1年前的代码,现在需要运行它。 欢迎任何可能的猜测。任何信息都会有帮助,谢谢 function getPrices(){ let url = 'https://url/api/Prices/v4?key=' + key; var massive; let quality = '5'; request({url:url, json:true}, function(err, res, body){ if (err) console.log(err);
function getPrices(){
let url = 'https://url/api/Prices/v4?key=' + key;
var massive;
let quality = '5';
request({url:url, json:true}, function(err, res, body){
if (err) console.log(err);
massive = body.response.items;
console.log('Prices received')
for(let i = 0; i < data.length; i += 1){
let get_json = other.urltojson(data[i].ApiLink);
let particle = get_json.particle
let name = data[i].BuyLink;
name = name.replace(/(\/Eligible).*/, '');
name = name.replace(/.*(\/)/, '');
name = name.replace(/\%20/g, ' ');
name = name.replace(/\%27/g, '\'')
let comPrice = massive[name].prices[quality].Eligible.Suitable[definition].value;
data[i].BuyPrice = comPrice;
}
});
}
此错误意味着massive[name].prices[quality]提供了未定义的
我不知道您的数据结构是怎样的,但可能是您将质量存储为字符串而不是整数
编辑:
如果massive[name].prices[quality]未定义,您可能有理由采取回退措施。似乎massive[name].prices[quality]没有价值。您是否尝试在浏览器开发工具中调试?如果您使用console.log massive[name].prices,它会给您带来什么?我正在用Sublime编辑此代码,因此无法真正进行调试。那么,您从哪里得到错误?@Victor F{'3':{Qualified:{Applied:{Array]},'6':{Qualified:{Applied:{Applied:{Applied:[Array],'Non:[Array]}}谢谢您的回复!请告诉我如何将质量存储为整数,而不是让质量='5';,不要让质量=5;5.你看到我对你的问题最后的评论了吗没有键为“5”的属性,这就是为什么它是未定义的“是的,我有。api的答案中有很多,但出于某种原因,代码没有看到它们
let comPrice = massive[name].prices[quality].Eligible.Suitable[definition].value;
^
TypeError: Cannot read property 'Eligible' of undefined