问题描述
我知道已经有这样的问题,但这并没有帮助我.
I know there already are questions like this, but It didn't help me.
我的网站上出现以下错误:
I get the follow error on my site:
该行是 <?= $bmstatus["networkConnections"] ?> p2p nodes
The line is <?= $bmstatus["networkConnections"] ?> p2p nodes
如果我print_r
$ bmstatus
,则得到:
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?
我已经尝试了$bmstatus['networkConnections']
和$bmstatus->networkConnections
但是两者都返回了该错误?
I've tried both $bmstatus['networkConnections']
and $bmstatus->networkConnections
but both is returning that error?
推荐答案
$bmstatus
包含JSON字符串.您必须先对其进行解码,然后才能从中提取所需的信息.为此,您可以使用内置函数 json_decode()
(第二个参数设置为TRUE
获取关联数组,而不是对象):
$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'];
这篇关于PHP:非法字符串偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!