简体   繁体   English

JSON / Javascript / JQuery 如何显示?

[英]JSON / Javascript / JQuery how do i display it?

I need help with javascript code, i want to display the:我需要 javascript 代码的帮助,我想显示:

AK-47 | AK-47 | Aquamarine Revenge (Battle-Scarred)海蓝宝石复仇(战痕累累)

i tried just copy pasting it like: "value.AK-47 | Aquamarine Revenge (Battle-Scarred)"我试着复制粘贴它:“value.AK-47 | Aquamarine Revenge (Battle-Scarred)”

but it didnt work但它没有用

  1. How do i put it into the " value. "?我如何将它放入“价值”中?
  2. i would like to display the "24_hours"-"average" but i don't know how to do it.我想显示“24_hours”-“average”,但我不知道该怎么做。
  3. If there are numbers how do i select them?如果有数字我怎么 select 他们?

Javascript: Javascript:

$.ajax({
    url: 'download.json',
    dataType: 'json',
    type: 'get',
    cache: false,
    success: function(data){
        $(data.items_list).each(function(index, value) {
            console.log(value. )));
        });
    }
});

JSON File: JSON 文件:

{
    "currency": "USD",
    "items_list": {
        "AK-47 | Aquamarine Revenge (Battle-Scarred)": {
            "classid": "1759174527",
            "exterior": "Battle-Scarred",
            "first_sale_date": "1432764000",
            "gun_type": "AK-47",
            "icon_url": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpot7HxfDhjxszJemkV09-5gZKKkPLLMrfFqWNU6dNoxL3H94qm3Ffm_RE6amn2ctWXdlI2ZwqB-FG_w-7s0ZK-7cjLzyE37HI8pSGKrIDGOAI",
            "icon_url_large": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpot7HxfDhjxszJemkV09-5gZKKkPLLMrfFqWNU6dNoteXA54vwxgCyqRVvZzrxItTDewY7NwvS_gW2x7y-h5a9vp3KnXZh63Ug4yyJyUepwUYbPABm4j8",
            "marketable": 1,
            "name": "AK-47 | Aquamarine Revenge (Battle-Scarred)",
            "price": {
                "24_hours": {
                    "average": 18.54,
                    "highest_price": 28.4,
                    "lowest_price": 15.85,
                    "median": 18.22,
                    "sold": "13",
                    "standard_deviation": "19.82"
                },
                "30_days": {
                    "average": 15.32,
                    "highest_price": 28.4,
                    "lowest_price": 8.31,
                    "median": 15.32,
                    "sold": "1611",
                    "standard_deviation": "8.96"
                },
                "7_days": {
                    "average": 16.5,
                    "highest_price": 28.4,
                    "lowest_price": 14.13,
                    "median": 16.4,
                    "sold": "400",
                    "standard_deviation": "9.18"
                },
                "all_time": {
                    "average": 12.42,
                    "highest_price": 32.68,
                    "lowest_price": 6.62,
                    "median": 14.25,
                    "sold": "170751",
                    "standard_deviation": "27.86"
                },
            },
        },
        
    }
}

Your question is quite confusing.你的问题很混乱。 Do you mean you want to fetch the string value from the JSON and display it through JQuery Foreach loop.您的意思是要从 JSON 获取字符串值并通过 JQuery Foreach 循环显示它。 'value' in here is the parameter which will hold the value(not the key) of the object from the first parameter of each() function.这里的“值”是参数,它将保存来自 each() function 的第一个参数的 object 的值(不是键)。

$.ajax({
url: 'download.json',
dataType: 'json',
type: 'get',
cache: false,
success: function(data){
    //Try it like this
    $.each(data['items_list'], function(index, value) {
        console.log(index)));
        console.log(value['name'])));
    });
}

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM