0

晚上好,我有一个 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,"UserId":7179424,"Projects":[{"user_id":7179424,"name":"Project1","color": 1,"is_deleted":0,"collapsed":0,"id":165361294,"archived_date":null,"item_order":1,"indent":1,"archived_timestamp":0,"shared":false, "is_archived":0},{"indent":1,"name":"Inbox","user_id":7179424,"color":7,"is_deleted":0,"collapsed":0,"inbox_project": true,"archived_date":null,"item_order":0,"is_archived":0,"archived_timestamp":0,"shared":false,"id":165339673}]}

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

TempIdMapping => {},

seq_no_global => 6201059540,

seq_no => 6201059540

等等...

4

1 回答 1

0

你的输出是 JSON 格式的,所以你可以json_decode像这样使用

json_decode($output, true);

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

于 2016-03-09T17:31:21.877 回答