Home > Backend Development > PHP Tutorial > php解析json的有关问题

php解析json的有关问题

WBOY
Release: 2016-06-13 11:21:37
Original
774 people have browsed it

php解析json的问题

	<br />$a = array(array('a','b','c','f','g'),'a'=>123);<br />$jsonStr = json_encode($a);<br />$e = json_decode($jsonStr);<br /><br />
Copy after login

通过print_r打印为:
stdClass Object ( [0] => Array ( [0] => a [1] => b [2] => c [3] => f [4] => g ) [a] => 123 )
如果我想获取123的值我直接$e->a;
但我想获取0里面的值应该怎么处理啊,对象属性名为0肯定是说不同的,这种情况应该怎么取值呢?


------解决方案--------------------
echo $e->{'0'}[1]; //b

通常用 $e = json_decode($jsonStr, true); 转换成数组就比较容易处理了
echo $e[0][1]; //b
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template