0

I'm currently reading someones inventory through

$inventory = file_get_contents("http://steamcommunity.com/profiles/{$Steam64}/inventory/json/730/2");

this is analog to

file_get_contents("http://api.steampowered.com/ISteamUser/GetplayerSummaries/v0002/?key={$api}&steamids={$Steam64}");

here i get steamid64 with

{$steam->response->players[0]->personaname}

How to get a specific element in the inventory's .json? For example:

{"success":true,"rgInventory":{"5904013658":{"id":"5904013658","classid":"469437901","instanceid":"302028390","amount":"1","pos":1},"5903531561":{"id":"5903531561","classid":"1293508920","instanceid":"0","amount":"1","pos":2},"5175566083":{"id":"5175566083","classid":"310780331","instanceid":"302028390","amount":"1","pos":3}

How to get classid? My solution above doesn't work for this :-(

aswell i need to read :

    pos":22}},"rgCurrency":[],"rgDescriptions":{"469437901_302028390":{"appid":"730","classid":"469437901","instanceid":"302028390","icon_url":"-9a81dlWLwJ2UUGcV

The icon_url and other stuff in this part.

Greetings

Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43
Zoetrope
  • 9
  • 7
  • Try to use `json_decode($response, true)` will convert associative array and you can work on it. – Abbasi Apr 26 '16 at 18:47
  • Possible duplicate of [Parsing JSON file with PHP](http://stackoverflow.com/questions/4343596/parsing-json-file-with-php) – Roy Falk Apr 26 '16 at 20:03
  • the problem is the 5904013658 or 469437901_302028390 i need them to get ids inside, but they change from user to user, they are not static, how do i fetch them? – Zoetrope Apr 26 '16 at 20:21

1 Answers1

0

it seems that your response is JSON try it as below:

$inventory = file_get_contents("http://steamcommunity.com/profiles/{$Steam64}/inventory/json/730/2");
$response = json_decode($inventory, true);

This will return you Associative array which you can access easily. e.g. $response['...']['...']

Abbasi
  • 617
  • 7
  • 14
  • thanks, that works for me, but the problem i have is the rgDescriptions":{"469437901_302028390":{"appid":"730 or "rgInventory":{"5904013658":{"id":"5904013658" the numbers 469...390 and 590...658, how can i get them? I need them for fatching the classid, but they change from player to player. For example i use: $t = "469437901_302028390"; $getitems = "{$inventory->rgDescriptions->$t->icon_url}"; but $t depends on the user and is always sometzhing else :/ – Zoetrope Apr 26 '16 at 19:17
  • please paste `vardump` of your `$response` – Abbasi Apr 26 '16 at 19:25
  • object(stdClass)#5 (6) { ["success"]=> bool(true) ["rgInventory"]=> object(stdClass)#6 (22) { ["5904013658"]=> object(stdClass)#7 (5) { ["id"]=> string(10) "5904013658" ["classid"]=> string(9) and ["rgCurrency"]=> array(0) { } ["rgDescriptions"]=> object(stdClass)#29 (18) { ["469437901_302028390"]=> object(stdClass)#30 (20) { ["appid"]=> string(3) "730" ["classid"]=> string(9) "469437901" ["instanceid"]=> string(9) "302028390" ["icon_url"]=> string(199) – Zoetrope Apr 26 '16 at 19:39