简体   繁体   English

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

[英]How to return and format an array in php by using curl

I know this maybe an easy question but I am still stuck here. 我知道这可能是一个简单的问题,但我仍然停留在这里。

I am calling an API, this is my code: 我正在调用一个API,这是我的代码:

   $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. 我将不胜感激。

That is JSON data...use json_decode() to convert to array 那就是JSON数据...使用json_decode()转换为数组

$arr = json_decode($content, TRUE);

$statuses = $arr['statuses'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM