Picking an item in a json without knowing the name

Good day all. I’m grabbing json info from a website and trying learn to list it but I’m running in to an issue outputting it. Every index in the json has a name and I’m wondering how I can spit them out one at a time without knowing each item’s name.

If it were a regular array I’d just do $json[0][1][3] or whatever but when I try to do it by number it gives me an Undefined offset error.

Here’s the code I’m using.

[php]<?php

 $url = 'https://api.opskins.com/IPricing/GetAllLowestListPrices/v1/?appid=440';
 $jsonData = file_get_contents($url);
 $json = json_decode($jsonData, true);

 echo $json['response'][1]['price'] . "<br><br><br><br>";

 echo '<pre>', print_r($json), '</pre>';

?>[/php]

So is there a way to call by the number of the index in json, or in lieu of that can I take the json info and convert it into a multidimensional array with numbers as the indexes?

Thanks for your time.

Why?

I’d like to be able to print out all of the items and their prices.

What is stopping you?

Lack of knowledge. lol

I want to create a loop that will increment the item and echo out its name and price but every time I try to put a number in

[php] echo $json[‘response’][1][‘price’] . “



”;[/php]

instead of the actual name of the item

[php] echo $json[‘response’][‘Name of The Item’][‘price’] . “



”;[/php]

it gives me an Undefined offset error.

Why are you using their old API?

Thanks for your time.

[php]<?php
$url = ‘https://api.opskins.com/IPricing/GetAllLowestListPrices/v1/?appid=440’;
$jsonData = file_get_contents($url);
$result = json_decode($json);

$items = $result->response;
?>

    <?php foreach ($items as $name => $data): ?>
  • <?= $name ?> $<?= $data->price ?> (<?= $data->quantity ?> in stock)
  • <?php endforeach; ?>
      [/php]

You have a name mismatch on line 3 and 4

Sponsor our Newsletter | Privacy Policy | Terms of Service