尝试使用 PHP 从 JSON 获取数据时获取通知


Getting Notices while trying to fetch data from JSON Using PHP

我用JSON获取了一些数据。然后我使用 json_decode() 将结果转换为 PHP 数组。现在,我正试图获得一些价值。 我收到通知。

$html = $curl->get($url);     // $html contains json result
$result = json_decode($html); //converting to php array
//the output is something like this
{
    "query":
        "results":{
           "Result":[
            {
              "BusinessUrl":"http://www.aplus.net/",
               -----------
               ------------
             }]
}

现在,如果我尝试像这样获取业务网址

$result->query->results->Result[0]->BusinessUrl

它给出了这样的通知

Notice: Trying to get property of non-object

请帮我解决这个问题。

尝试

$result->query->results->Result[0]['BusinessUrl']

我的猜测是,一旦你在 JSON 中遇到一个数组,你就只能从数组而不是对象访问所有内容。