dptt66700 2016-10-04 01:46
浏览 74
已采纳

如何使用curl在php中返回和格式化数组

I know this maybe an easy question but I am still stuck here.

I am calling an API, this is my code:

   $access_token = 'asdfasdfasdfasdf';
   $uid = '12345678';
   $url = 'https://api.asd.com/2/statuses/user_timeline/ids.json?uid='.$uid.'&access_token='.$access_token.'&count=5';
   $ch = curl_init();
   curl_setopt($ch,CURLOPT_HEADER,false);
   curl_setopt($ch,CURLOPT_URL,$url);
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
   $content=curl_exec($ch);
   curl_close($ch);
   echo $content;

This is what I got:

{
    "statuses":"4023805771256802","4023694609717194","4021770053107357","4021769599890997","4021769217975680"],
    "marks":[],
    "hasvisible":false,
    "previous_cursor":0,
    "next_cursor":0,
    "total_number":94,
    "interval":0,
    "uve_blank":0
}

What I want is having an array of 'statuses' only, because I want to use the data in 'statuses' only.

Anyone can give me a hint? I will be really appreciated.

  • 写回答

1条回答 默认 最新

  • doujun1495 2016-10-04 01:56
    关注

    That is JSON data...use json_decode() to convert to array

    $arr = json_decode($content, TRUE);
    
    $statuses = $arr['statuses'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示