0
我使用亞馬遜的產品API,我用ASIN號搜索一個項目:如何獲取json文件中特定元素的值? (亞馬遜API)
amazon = require('amazon-product-api');
var client = amazon.createClient({
awsId: "*",
awsSecret: "*",
awsTag: "Tag"
});
client.itemLookup({
idType: 'ASIN',
itemId: 'B00WA6ZL8S',
responseGroup :'Variations'
}).then(function(results) {
console.log(JSON.stringify(results));
}).catch(function(err) {
console.log(err);
});
結果是有超過40000行代碼很長的JSON文件,這裏是一些它:
[{
"ASIN": ["B00WA6ZL8S"],
"ParentASIN": ["B00WA6ZL8S"],
"VariationSummary": [{
"LowestPrice": [{
"Amount": ["9200"],"CurrencyCode": ["USD"], "FormattedPrice": ["$92.00"]
}],
"HighestPrice": [{
"Amount": ["13995"],
"CurrencyCode": ["USD"],
"FormattedPrice": ["$139.95"]
}]
}],
"Variations": [{
"TotalVariations": ["48"],
"TotalVariationPages": ["1"],
"VariationDimensions": [{
"VariationDimension": ["Size", "Color"]
}],
"Item": [{
"ASIN": ["B00RHLICFA"],
"ParentASIN": ["B00WA6ZL8S"],
"SmallImage": [{
"URL": ["http://ecx.images-amazon.com/images/I/41z-SPDeICL._SL75_.jpg"],
"Height": [{
"_": "35",
"$": {
"Units": "pixels"
}
}],
"Width": [{
"_": "75",
"$": {
"Units": "pixels"
}
}]
}],
如何獲得高度或寬度等的值? 「VariationSummary」中的方括號有什麼意義:[{或「Variations」:[{??我的意思是他們不是對象的數組! 。
不工作,它給了我一個錯誤:[TypeError:無法讀取屬性'高度'未定義] –
我修正了錯誤,現在試試.SmallImage [0]包含高度。 – deek
[TypeError:無法讀取屬性'SmallImage'的undefined] –