duange2971 2016-09-08 21:59
浏览 26

如何使用php访问json数组的特定字段

I am trying to access the json data from an API, and displaying it on the webpage for the time being. I am able to fetch the data array, but I want only 1 field in that data. Below is my code.

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'ACCEPT: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL,"https://www.localmed.com/providers/us_0651651651_9vg5u1r2g1tw3e5_f24c866/openings/?reasonForVisitId=us_1223_new_teethcleaning-adult");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


curl_setopt($ch, CURLOPT_HEADER, false);
$result = curl_exec($ch);
curl_close($ch);

//$json_a=json_decode($result,true);
var_dump(json_decode($result, true));
var_dump ($result[1]['time']); 

Below are the results,

I need to get only the 'time' field. please help. I am getting error undefined index 'time'

array (size=1)
  'openings' => 
   array (size=10)
    0 => 
    array (size=4)
      'id' => string 'us_0651651651_9vg5u1r2g1tw3e5_f24c866_20160909T130000Z_67cbe00' (length=62)
      'uri' => string '/providers/us_0651651651_9vg5u1r2g1tw3e5_f24c866/openings/us_0651651651_9vg5u1r2g1tw3e5_f24c866_20160909T130000Z_67cbe00/' (length=121)
      'display' => null
      'time' => string '2016-09-09T13:00:00Z' (length=20)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿