在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/數(shù)據(jù)分析&挖掘  Java  PHP  Linux  網(wǎng)絡(luò)安全/ php 印出 json array一直失敗?

php 印出 json array一直失敗?

{
    "list": [
        {
            "attribute-id": "f11",
            "name": "love",
            "type": "me"
        },
        {
            "attribute-id": "f12",
            "name": "member",
            "type": "her"
        },
        {
            "attribute-id": "f13",
            "name": "user",
            "type": "her"
        },
        {
            "attribute-id": "f14",
            "name": "like",
            "type": "me"
        }
    ]
}

我利用curl跟別人的後端api撈過(guò)來(lái)以上的數(shù)據(jù)
對(duì)方的需求是要告知type

$data = array(
  "type" => "skill"
);
$data_string = json_encode($data);

$result = curl_exec($ch);

於是我印出 echo $result,取得的結(jié)果是同一個(gè)type沒(méi)錯(cuò)

但我想在我這端用php印出來(lái)
例如所有的名字

foreach($result->list as $mydata)

    {
         echo $mydata->name;

    }

但這樣卻沒(méi)辦法印出
Notice: Trying to get property 'list' of non-object
Warning: Invalid argument supplied for foreach()

是哪裡有問(wèn)題?!

回答
編輯回答
淺時(shí)光

需要先將$result結(jié)果使用$result = json_decode($result, true);解析為數(shù)組,之后再執(zhí)行如下操作

foreach($result['list'] as $mydata)
{
    echo $mydata['name'];
}
2018年5月3日 03:29