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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?