如果您的PHP数组中的数组键不是连续的数字,则json_encode() 必须使另一个构造成为一个对象,因为JavaScript数组总是连续地进行数字索引。array_values()在PHP的外部结构上使用,以丢弃原始的数组键,并将其替换为从零开始的连续编号:例:// Non-consecutive 3number keys are OK for PHP// but not for a JavaScript array$array = array( 2 => array("Afghanistan", 32, 13), 4 => array("Albania", 32, 12));// array_values() removes the original keys and replaces// with plain consecutive numbers$out = array_values($array);json_encode($out);// [["Afghanistan", 32, 13], ["Albania", 32, 12]]