Todoist API - 从字符串到数组

时间:2016-03-09 17:23:48

标签: php curl

晚上好,我有关于Todoist的帐户。我会使用Todoist API来获取所有项目。我写了以下代码:

$url = "https://todoist.com/API/v6/sync";
$post_data = array(
    'token' => "12345678901234567890abcdefabcdef01234567",
    'seq_no' => "0",
    'resource_types' => '["projects"]'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$output = curl_exec($ch);

print_r($output);

curl_close($ch);

输出是这样的字符串:

  

{" TempIdMapping":{}," seq_no_global":6201059540," seq_no":6201059540,"用户ID":7179424,& #34;项目":[{" USER_ID":7179424,"名称":" PROJECT1""颜色":1, " IS_DELETED":0,"折叠":0," ID":165361294" archived_date":空," item_order&# 34;:1,"缩进":1," archived_timestamp":0,"共享":假," is_archived":0}, {"缩进":1,"名称":"收件箱"" USER_ID":7179424,"颜色&#34 ;: 7," IS_DELETED":0,"折叠":0," inbox_project":真," archived_date":空," item_order":0," is_archived":0," archived_timestamp":0,"共享":假," ID":165339673 }]}

有没有办法将此输出转换为数组? 例如:

TempIdMapping => {},

seq_no_global => 6201059540,

seq_no => 6201059540

依旧......

1 个答案:

答案 0 :(得分:0)

您的输出是JSON格式化的,因此您可以像这样使用json_decode

json_decode($output, true);

第二个参数将结果转换为关联数组而不是stdObject