如何使用PHP从JSON对象访问变量

时间:2019-05-31 11:22:04

标签: php json

我有json数据,需要从json数据中检索URL对象

{
  "_type": "SearchResponse",
  "queryContext": {
    "originalQuery": "Buford city, planning commission, GWINNETT county, ga"
  },
  "webPages": {
    "webSearchUrl": "https://www.bing.com/search?q=Buford+city%2c+planning+commission%2c+GWINNETT+county%2c+ga",
    "totalEstimatedMatches": 296000,
    "value": [
      {
        "id": "https://api.cognitive.microsoft.com/api/v7/#WebPages.0",
        "name": "City of Buford - Planning and Zoning Department",
        "url": "https://cityofbuford.com/PlanningZoning.aspx",
        "about": [
          {
            "name": "Buford"
          }
        ]
    }
    }
    }
$response = $request->send();
    //  echo $response->getBody();
    $JsonData= $response->getBody();
    $data=json_decode($JsonData,true);
        foreach($data as $chunk)
     {
      echo $data[1];
     }

“ URL”:“ https://cityofbuford.com/PlanningZoning.aspx” 需要访问该对象

0 个答案:

没有答案