Json和php:如何解析这个数组(对象)
我有一个JSON响应:Json和php:如何解析这个数组(对象),php,json,Php,Json,我有一个JSON响应: object(stdClass)#1 (2) { ["data"]=> array(47) { [0]=> object(stdClass)#2 (4) { ["id"]=> int(341) ["competition_id"]=> int(1) ["name"]=> string(9) "2015/2016" ["active"]=
object(stdClass)#1 (2) {
["data"]=>
array(47) {
[0]=>
object(stdClass)#2 (4) {
["id"]=>
int(341)
["competition_id"]=>
int(1)
["name"]=>
string(9) "2015/2016"
["active"]=>
bool(true)
但我不知道如何解析数据
我用以下PHP代码进行了尝试:
echo $json->data[0]->id;
但它不起作用。例如,如何获取ID?以下是我的解决方案:
$json = file_get_contents($url);
$json2 = json_decode($json);
echo $json2->data[0]->id;
很抱歉,我们的目标是json_decode()函数,之后我可以使用“->”获取数据
你好 您的响应不是JSON…抱歉,这是JSON_decode()方法的输出…然后
echo$JSON->data[0]->id
应该可以工作。或者您想要所有$json->data
数组属性中的数据吗?在我发现它的同时:p谢谢!