[英]How to parse JSON string in php
I'm getting below JSON response: 我得到下面的JSON响应:
[{"startDate":"2012-07-12 11:21:38 +0530","totalTime":0},{"startDate":"2012-07-11 11:27:33 +0530","totalTime":0},{"startDate":"2012-07-16 18:38:37 +0530","totalTime":0},{"startDate":"2012-07-17 14:18:32 +0530","totalTime":0}]
i want make array of start date and totalTime, i have used these two lines but it wont work $obj, please suggest.. 我想使数组的开始日期和totalTime,我已经使用了这两行,但它不会工作$ obj,请建议..
$obj = json_decode($dateTimeArr);
$dateAr = $obj->{'startDate'};
这很简单:
$Arr = json_decode($JSON, true);
As everyone said, and you did - use json_decode
. 就像大家说的那样,您确实做到了-使用
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. 将来,如果不确定变量中的数据类型或结构,请执行
var_dump($var)
,它将打印变量的类型及其内容。
json_decode()
将为您提供嵌套的PHP类型,然后您可以将其下降以检索数据。
使用json_decode($ json_response,true)将json转换为Array
Guess what you are looking for is json_decode()
猜你在找什么是
json_decode()
Check out http://php.net/manual/en/function.json-decode.php for the inner workings 查看http://php.net/manual/en/function.json-decode.php的内部工作原理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.