doubeizhong5178 2019-02-18 21:46
浏览 286
已采纳

问题处理来自cURL请求的JSON响应

I'm trying to handle the response from a cURL request that returns a JSON with some date and other data i don't need. I'm trying to access the data from the dates to show them in a calendar in my app, but I'm not able to access the information at all. I've checked other similar questions but none of the solutions worked for me. This is my code:

<?php
$data = "{}";
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://******",
  CURLOPT_POST => 1,
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_FOLLOWLOCATION => true,
));


$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$decode = json_decode($response, true);
var_dump($decode);
var_dump($response);

This is the response i get:

{
calendar: {
holidays: [
"12/10/2018",
"01/11/2018",
"09/11/2018",
"06/12/2018",
"19/04/2019",
"01/05/2019"
],
nonTeaching: [
"24/12/2018",
"02/11/2018",
"26/12/2018",
"07/12/2018",
"27/12/2018",
"12/04/2019",
"28/12/2018",
"03/05/2019",
"28/04/2019"
],
events: [
{
other info
}

I'm trying to access the dates from holidays and nonTeaching, but so far I haven't been able to. The var_dump just returns "1" or true.

What am I doing wrong?

Thank you very much in advance.

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 基于香农-费诺-埃利斯编码实现对英文文本的压缩和解压缩
      • ¥15 react native ios端amap问题
      • ¥15 fortran95中5个学生分不同学号求数学语文英语计算机四门课程的每名学生的平均分以及名次以及单科成绩的平均分
      • ¥30 excel vba 执行从 1 到 100 的乘法。执行结果保存成二维数组
      • ¥15 数字电子技术基础设计实验
      • ¥15 ue5运行非常卡顿,是电脑配置原因吗
      • ¥50 有没有大佬看一下关于思科的这道题怎么做
      • ¥30 求十字路口交通灯S7-200plc,今天早上八点前。
      • ¥20 如何用智能手表oppowatch3实现个人热点功能
      • ¥15 运营商打开wanpush会有怎么样的危害