I\'m getting below JSON response:
[{\"startDate\":\"2012-07-12 11:21:38 +0530\",\"totalTime\":0},{\"startDate\":\"2012-07-11 11:27:33 +0530\",\"totalTime\":0
It is very easy:
$Arr = json_decode($JSON, true);
json_decode() will give you nested PHP types you can then descend to retrieve your data.
As everyone said, and you did - use json_decode
.
$dateArrays = json_decode($dateTimeArr, true); // decode JSON to associative array
foreach($dateArrays as $dateArr){
echo $dateArr['startDate'];
echo $dateArr['totalTime'];
}
In future, if you are unsure what type or structure of data is in the variable, do var_dump($var)
and it will print type of variable and its content.
Guess what you are looking for is json_decode()
Check out http://php.net/manual/en/function.json-decode.php for the inner workings
use json_decode($json_response,true) to convert json to Array