Todoist API - 将输出从字符串转换为数组

Todoist API - convert output from a string to array

晚上好,我在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

等等...

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

json_decode($output, true);

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