我想通过JavaScript从网站读取json数据。 JSON看起来是这样的:通过Javascript读取Json数据
{
"status" : "success",
"prices" : [
{
"market_hash_name" : "AK-47 | Aquamarine Revenge (Battle-Scarred)",
"price" : "11.38",
"created_at" : 1460116654
},
所以,我得到了代码:
if(pricelist.prices.market_hash_name == itemName) {
var price2 = Math.round(Number(pricelist.prices.market_hash_name[itemName].price) * 1000);
我知道我错了,在这里做什么,可能有人帮助我吗?
编辑:该功能是在这里:
function loadItems() {
$("#refresh-button").remove();
$("#loading").addClass("active");
$.getJSON("" + bot_sids[cur_bot], function(data) {
if (data.success) {
var i = 0;
var ready = true;
var invIndexes = [];
for (var index in data.rgInventory) {
invIndexes[i] = index;
i++;
}
i = 0;
$.getJSON("", function(pricelist) {
apricething = pricelist;
if (pricelist.status) {
for (id = 0; id < invIndexes.length; id++) {
var index = invIndexes[id];
var item = data.rgDescriptions[data.rgInventory[index].classid + "_" + data.rgInventory[index].instanceid];
if (item.tradable != 1) {
continue;
}
var itemName = item.market_hash_name;
var iconUrl = item.icon_url;
console.log(itemName);
for(i=0; i<pricelist.prices.length; i++){
if (pricelist.prices[i].market_hash_name == itemName) {
var price2 = Math.round(Number(pricelist.prices[i].market_hash_name.price) * 1000);
console.log(itemName);
console.log(price2);
if (price2 >= 1) {
prices2[itemName] = price2;
items[id] = {
name: itemName,
price: price2,
iconurl: iconUrl,
classid: data.rgInventory[index].classid,
id: index,
done: true
};
} else {
items[id] = {
done: true
};
}
} else {
items[id] = {
name: itemName,
price: 0,
iconurl: iconUrl,
classid: data.rgInventory[index].classid,
id: index,
done: false
};
}
}
}
finishedLoading();
}
});
是什么问题?错误?您想做什么? –
它不适合我,它没有达到那个价格2。如果它会到达那里,我会去:console.log(price2); –
您能否将此减少到20-30行代码,以便我们可以看到发生了什么? –