简体   繁体   English

从JSON,Node.js获取值

[英]Getting a value from JSON, Node.js

I am having trouble with getting a value from inside of a JSON file, which has been retrieved from the Steam API ( http://steamcommunity.com/dev ). 我无法从JSON文件中获取值,该文件已从Steam API( http://steamcommunity.com/dev )中检索到。

The problem occurs when I attempt to print the data, the Node.js file code is below: 当我尝试打印数据时,会出现问题,Node.js文件代码如下:

var data = JSON.parse(body); // Stores the JSON data which has been retrieved
console.log(data.result.toString(350462890).market_hash_name); // Attempts to grab the value of the market_hash_name from the JSON data and display it to screen

I get the following response: "undefined". 我收到以下响应:“未定义”。

JSON data used below: JSON数据如下:

{
"result": {
    "350462890": {
        "icon_url": "fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZYMUrsm1j-9xgEObwgfEh_nvjlWhNzZCveCDfIBj98xqodQ2CZknz5-OOqhNQh0fTvSAK5KVPAoywXpDS4n5YliBtazruNQfgrssNfPN-IqYtkdSpTZU_OCYAir70luiaAPfZOIqHznw223bZvDH3kW",
        "icon_url_large": "fWFc82js0fmoRAP-qOIPu5THSWqfSmTELLqcUywGkijVjZYMUrsm1j-9xgEObwgfEh_nvjlWhNzZCveCDfIBj98xqodQ2CZknz5-OOqhNQh0fTvSAK5KVPAoywXpDS4n5fhvVcWx8vUHe126vYrANLYvNI1FG5LWCPfXM1304048hqALKpffqSu9jyvoMjgCRVO1rexMsCC1",
        "icon_drag_url": "",
        "name": "Dual Berettas | Panther",
        "market_hash_name": "Dual Berettas | Panther (Field-Tested)",
        "market_name": "Dual Berettas | Panther (Field-Tested)",
        "name_color": "D2D2D2",
        "background_color": "",
        "type": "Mil-Spec Grade Pistol",
        "tradable": "1",
        "marketable": "1",
        "commodity": "0",
        "fraudwarnings": "",
        "descriptions": {
            "0": {
                "type": "html",
                "value": "Exterior: Field-Tested",
                "app_data": ""
            },
            "1": {
                "type": "html",
                "value": " ",
                "app_data": ""
            },
            "2": {
                "type": "html",
                "value": "Firing two large-mag Berettas at once will lower accuracy and increase load times. On the bright side, you'll get to fire two large-mag Berettas at once. It has been painted in a black, grey and red color scheme.",
                "app_data": ""
            },
            "3": {
                "type": "html",
                "value": " ",
                "app_data": ""
            },
            "4": {
                "type": "html",
                "value": "The Arms Deal 3 Collection",
                "color": "9da1a9",
                "app_data": {
                    "def_index": "65535",
                    "is_itemset_name": "1"
                }
            },
            "5": {
                "type": "html",
                "value": " ",
                "app_data": ""
            }
        },
        "owner_descriptions": "",
        "actions": {
            "0": {
                "name": "Inspect in Game...",
                "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S%owner_steamid%A%assetid%D14429613083935122456"
            }
        },
        "market_actions": {
            "0": {
                "name": "Inspect in Game...",
                "link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D14429613083935122456"
            }
        },
        "tags": {
            "0": {
                "internal_name": "CSGO_Type_Pistol",
                "name": "Pistol",
                "category": "Type",
                "category_name": "Type"
            },
            "1": {
                "internal_name": "weapon_elite",
                "name": "Dual Berettas",
                "category": "Weapon",
                "category_name": "Weapon"
            },
            "2": {
                "internal_name": "set_weapons_iii",
                "name": "The Arms Deal 3 Collection",
                "category": "ItemSet",
                "category_name": "Collection"
            },
            "3": {
                "internal_name": "normal",
                "name": "Normal",
                "category": "Quality",
                "category_name": "Category"
            },
            "4": {
                "internal_name": "Rarity_Rare_Weapon",
                "name": "Mil-Spec Grade",
                "category": "Rarity",
                "color": "4b69ff",
                "category_name": "Quality"
            },
            "5": {
                "internal_name": "WearCategory2",
                "name": "Field-Tested",
                "category": "Exterior",
                "category_name": "Exterior"
            }
        },
        "classid": "350462890"
    },
    "success": true
}

} }

So does anyone have any idea how I can return the market_hash_name? 那么,有人知道我如何返回market_hash_name吗? also please take note, I am fairly new to using Node.js. 还请注意,我对使用Node.js相当陌生。

data.result['350462890'].market_hash_name

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

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