I have a REST API that returns a list of tasks in JSON Format, I decode it into an array using :
$decoded = json_decode($curl_response,true);
and am having trouble in using that array.
EDIT : Sorry for modifying question but the curl_response is
{
"error": true,
"message": "Api key is misssing"
}
When I login there is an API key in JSON response, I don't know how to use further. That key is required for authentication in any further call of API. How to include that apikey in my request header for further curl calls?
The response is of the form (as tested using Advanced REST Client in Chrome):
{
error: false
tasks: [5]
0: {
id: 2
task: "[email protected]"
status: 0
createdAt: "2014-10-21 21:42:48"
}-
1: {
id: 3
task: "Inter Nam"
status: 0
createdAt: "2014-10-21 21:42:58"
}-
2: {
id: 4
task: "Vamos"
status: 0
createdAt: "2014-10-21 21:43:04"
}-
3: {
id: 5
task: "El Mundo"
status: 0
createdAt: "2014-10-21 23:12:33"
}-
4: {
id: 6
task: "El Clasico"
status: 0
createdAt: "2014-10-21 23:12:45"
}-
-
}
I tried to decode the above response in an array $decoded and then I want to display each task in a loop, get total no. of tasks..etc. --------------------------------(1)
Using Count($decoded) I get 2 which is clearly wrong, also I am unable to to get the individual tasks using :
foreach($decoded as $task) {
echo $task["task"];
}
How to implement (1) ?
tasksitem;foreach ($decoded['tasks'] as $task).$curl_response