I know there already are questions like this, but It didn't help me.
I get the follow error on my site:
Warning: Illegal string offset 'networkConnections' in /var/www/bitmsg/templates/header.php on line 25 {
The line is
    
<?= $bmstatus["networkConnections"] ?> p2p nodes
if I print_r $bmstatus, then I get:
{
    "numberOfBroadcastsProcessed": 2308,
    "networkStatus": "connectedAndReceivingIncomingConnections",
    "softwareName": "PyBitmessage",
    "softwareVersion": "0.4.1",
    "networkConnections": 52,
    "numberOfMessagesProcessed": 22888,
    "numberOfPubkeysProcessed": 8115
}
How to I fetch the information from this array?
I've tried both $bmstatus['networkConnections'] and $bmstatus->networkConnections
but both is returning that error?
$bmstatus contains a JSON string. You have to decode it first to be able to extract the required information out of it. For this purpose, you can use the built-in function json_decode() (with the second parameter set as TRUE to get an associative array, instead of an object):
$json = json_decode($bmstatus, true);
echo $json['networkConnections'];
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With