1
我試圖從Rembmer the Milk API檢索任務。我運行此代碼:PHP不能使用字符串偏移量作爲數組錯誤
$array = json_decode($content, true);
foreach($array['rsp']['tasks']['list']['taskseries'] as $keys=>$val) {
$task = $val['name'];
$duedate = $val['task']['due'];
echo $task." ";
echo $duedate."<br>";
}
,但我收到此錯誤:
致命錯誤:無法使用字符串在C數組offset:**上線66
(第66行是$交貨期= $ VAL ['task'] ['due'];)
這是我試圖解碼的JSON響應(試圖獲得「name」:「SOMETHING」和「due」:「2011-03-17T04:00 :00Z「:
{"rsp":{"stat":"ok","tasks":{"rev":"[CODE]","list":{"id":"[ID NUMBER]","taskseries": {"id":"ID","created":"DATE CREATED","modified":"DATE","name":"SOMETHING","source":"js","url":"","location_id":"","tags":[],"participants":[],"notes":[],"task":{"id":"ID","due":"2011-03-17T04:00:00Z","has_due_time":"0","added":"DATE","completed":"","deleted":"","priority":"1","postponed":"0","estimate":""}}}}}}
如何修復? Tha NKS !!!!!
UPDATE 這是兩個或兩個以上任務的JSON響應:
{"rsp":{"stat":"ok","tasks":{"rev":"NUMBER","list":{"id":"ID NUMBER","taskseries":[{"id":"ID NUMBER","created":"CREATED DATE","modified":"DATE","name":"TASK 3","source":"js","url":"","location_id":"","tags":[],"participants":[],"notes":[],"task":{"id":"ID","due":"2011-03-18T04:00:00Z","has_due_time":"0","added":"DATE","completed":"","deleted":"","priority":"1","postponed":"0","estimate":""}},{"id":"ID","created":"DATE","modified":"DATE","name":"SOMETHING","source":"js","url":"","location_id":"","tags":[],"participants":[],"notes":[],"task":{"id":"ID","due":"2011-03-17T04:00:00Z","has_due_time":"0","added":"DATE","completed":"","deleted":"","priority":"1","postponed":"0","estimate":""}}]}}}}
的API可以在相同的JSON代碼中返回多個任務,只是沒有在顯示的代碼...這就是爲什麼我需要foreach循環... – 01jayss 2011-03-18 03:11:18
@ 01jayss:你能否更新顯示一個示例響應與多個任務的問題? – icktoofay 2011-03-18 03:13:04
根據您的要求更新 – 01jayss 2011-03-18 03:50:16