-1

Below is my data get from API , I try to display the shopId, Shopname and shopcode but failed.Any one can help me solve this problem ? I am using the PHP to write the script and get API data.Below is my script to get API data.

   <?php      
    $get = file_get_contents("http://api.meirenji.cn/api/xxxxxxxxxxx");
    $json = json_decode($get);

    $shop_id = $json->content->shopId;
    echo "Shop ID : ".$shop_id."";
    ?>

Below is the data that i get from API, it have multiple array data, i nee get data shopId, Shopname,shopcode

stdClass Object
(
    [status] => 0
    [msg] => succes
    [content] => Array
        (
            [0] => stdClass Object
                (
                    [shopId] => 6674
                    [shopname] => SP
                    [shopcode] => 38862185
                    [type] => shop
                    [flag] => 1
                )

            [1] => stdClass Object
                (
                    [shopId] => 6498
                    [shopname] => Adidas
                    [shopcode] => 74812597
                    [type] => shop
                    [flag] => 1
                )

            [2] => stdClass Object
                (
                    [shopId] => 6498
                    [shopname] => Nike 
                    [shopcode] => 98741852
                    [type] => shop
                    [flag] => 1
                )

            [3] => stdClass Object
                (
                    [shopId] => 6501
                    [shopname] => Puma
                    [shopcode] => 13847915
                    [type] => shop
                    [flag] => 1
                )

            [4] => stdClass Object
                (
                    [shopId] => 6509
                    [shopname] => Adidas NEO
                    [shopcode] => 26700485
                    [type] => shop
                    [flag] => 1
                )

            [5] => stdClass Object
                (
                    [shopId] => 6865
                    [shopname] => Testing Unit
                    [shopcode] => 23891935
                    [type] => shop
                    [flag] => 1
                )

            [6] => stdClass Object
                (
                    [shopId] => 9661
                    [shopname] => UNDER ARMOR
                    [shopcode] => 88741294
                    [type] => shop
                    [flag] => 1
                )
        )
)
Lawrence
  • 13
  • 6

1 Answers1

0

To get shopname and shopcode from your response object, you've to loop over your content like this way using foreach(),

foreach($json->content as $key=>$row){
  echo "shopname = $row->shopname and shopcode = $row->shopcode". PHP_EOL; 
}

DEMO: https://3v4l.org/tWqt7

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103