在包装类中使用API​​的json_decode不会产生输出[重复]

This question already has an answer here:

I need an help for displaying a JSON code in this code actually when I run it get an empty page but I want to get a json code result but am not getting I just wanna see how to get it

Code :-

<?php
class Api
{
    const API_URL = 'http://yoursite/api/v2'; // API URL/Replace reseller domain
    const API_TOKEN = ''; // Your API token

    public function order($data) { // add order
        $post = array_merge([
            'api_token' => self::API_TOKEN,
            'action' => 'add'
        ], $data);

        return json_decode($this->connect($post));
    }

    public function status($order_id) { // get order status
        return json_decode($this->connect([
            'api_token' => self::API_TOKEN,
            'action' => 'status',
            'order' => $order_id
        ]));
    }

    public function balance() { // get balance
        return json_decode($this->connect([
            'api_token' => self::API_TOKEN,
            'action' => 'balance',
        ]));
    }

   public function packages() { // get packages list
        return json_decode($this->connect([
            'api_token' => self::API_TOKEN,
            'action' => 'packages',
        ]));
    }

    private function connect($post) {
        $_post = Array();
        foreach ($post as $name => $value) {
            $_post[$name] = urlencode($value);
        }

        $ch = curl_init(self::API_URL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));

        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        $result = curl_exec($ch);
        if (curl_errno($ch) != 0 && empty($result)) {
            $result = false;
        }
        curl_close($ch);
        return $result;
    }
}

// Examples

$api = new Api();

// Fetch Packages
$packages = $api->packages();

// Check balance
$balance = $api->balance();

// Add order
$order = $api->order(array('package' => 1, 'link' => 'http://example/link', 'quantity' => 100));

// Add Custom comments order
$order = $api->order(array('package' => 11, 'link' => 'http://example/link', 'quantity' => 4, 'comments' => "good pic
great photo
:)
;)")); # Custom Comments

// Check Order status
$status = $api->status($order->order);

In this code am just getting a blank page but I want to output the Public function balance () I wanna output the JSON response just help mep Me

How to output it's json_decode? Please help me

</div>

As comments have said, you need to output a Variable.

print_r($order);
print_r($status);

I'm using print_r because it gives you a nice display of an Array value. Which is most likely what you are gonna get back from your json_decode.

Side note: The current way you are using json_decode you will have to refer to variables like

$order->id

But if you want to access them as arrays

$order['id'] 

Then you need to use json_decode like this

json_decode($json, true); // The True value is important

PHP docs json_decode