Home  >  Article  >  Backend Development  >  php json_encode问题

php json_encode问题

WBOY
WBOYOriginal
2016-06-23 14:15:38855browse

php json_encode PHP JSON json_encode

rt小弟今天遇到个奇怪的问题

只是使用json_encode转换的json编码,圈出的地方是应该是个自然序列下标数组,可不知为何转换成了对象,但下标却标记为0,请了解的大神们为小弟出出主意,谢谢了。

回复讨论(解决方案)

建议把你的代码贴出来以供分析。

当数组的下标不以0开始递增连续时,就是关联数组了

$ar =array(1=>'a',0=>'b');echo json_encode($ar); //{"1":"a","0":"b"}$ar =array('a',2=>'b');echo json_encode($ar); //{"0":"a","2":"b"}

代码就是$json = json_encode($array, true);

Statement:
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