0

下面是我尝试使用 php 解析的示例 json 代码。

{
    "educations": {
        "_total": 7
    }
}

我尝试使用以下 php 代码对其进行解析。但我犯了一些我无法找到的愚蠢错误。下面是PHP代码

<?php

$decoded = json_decode($json_string)
echo "$decoded->educations->_total";

?>

但我没有得到一些我无法弄清楚的对象错误。

错误是:可捕获的致命错误:stdClass 类的对象无法转换为字符串

请帮助谢谢。

4

2 回答 2

0

尝试将返回的 json 对象作为数组访问

$total = $decoded['educations']['_total'];
于 2013-09-16T21:30:06.070 回答
0

对不起我的愚蠢错误:

$total= "$decoded->educations->_total";

我添加了造成此问题的双引号。下面的代码是正确的。

<?php

$decoded = json_decode($json_string)
echo $decoded->educations->_total;

?>
于 2013-09-16T21:50:33.070 回答