简体   繁体   English

CSGO-如何从JSON显示用户清单

[英]CSGO - How to display a users inventory from the JSON

I'm wanting to make a system that gets a users inventory then displays it as the image and name. 我想制作一个可以获取用户清单,然后将其显示为图像和名称的系统。 I only know how to do the JSON part and I'm unsure as what to do next. 我只知道怎么做JSON部分,我不确定下一步该怎么做。

All I have at the moment is: 我目前所拥有的是:

http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/753/1

Is anyone able to help me turn that data into what I am looking for? 有人能帮助我将数据变成我想要的东西吗?

First off - for CS:GO, at least - the URL you are looking for is: 首先-对于CS:GO,至少-您要查找的URL是:

http://steamcommunity.com/profiles/<PROFILEID>/inventory/json/730/2

The two numbers at the end of the URL refer to the app ID and context ID, respectively. URL末尾的两个数字分别表示应用程序ID和上下文ID。 CS:GO's app ID is 730 and most games use a context ID of 2 for user inventories. CS:GO的应用程序ID为730,大多数游戏的用户清单使用上下文ID 2。

The JSON returned from this request is an object in the following format: 从此请求返回的JSON是以下格式的对象:

{
    "success": true,
    "rgInventory": { ... },
    "rgCurrency": { ... },
    "rgDescriptions": { ... },
    "more": false,
    "more_start": false
}

For the use-case you described (getting the item names and icons), you can ignore everything except the rgDescriptions object. 对于您描述的用例(获取项目名称和图标),可以忽略除rgDescriptions对象之外的所有内容。 This object contains an object for each item in the user's inventory. 该对象包含用户库存中每个项目的对象。 The object keys are the result of concatenating the item's classid and instanceid , but that doesn't really matter for you - you can just iterate over it like you would for any other object. 对象键是连接项目的classidinstanceid ,但这对您来说并不重要-您可以像对其他任何对象一样对其进行迭代。

The two data points that you're interested in are market_hash_name , which is the name of the item, and icon_url , which is part of what you need to display the actual image. 您感兴趣的两个数据点是market_hash_name (这是商品的名称)和icon_url (这是显示实际图像所需的一部分)。 The full path to the image is https://steamcommunity-a.akamaihd.net/economy/image/{icon_url} . 图像的完整路径是https://steamcommunity-a.akamaihd.net/economy/image/{icon_url} For example, this link loads the icon for a G3SG1 | 例如, 此链接加载G3SG1 |的图标。 Polar Camo in my inventory. 我的库存中有极地迷彩。

One thing to note is that the market_hash_name includes the wear pattern (eg, Minimal Wear, Factory New, etc.). 需要注意的一件事是market_hash_name包含磨损模式(例如,最小磨损,崭新出厂等)。 If you don't need those, you can just use the name from the object. 如果不需要这些,则可以使用对象中的name

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

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