我在这里查了几篇文章,但没有一篇能为我效劳。 我有一个json_encode函数接收一个在localhost上工作得很好但在生产Web服务器上没有工作的数组。
嗯,php版本是5.6.17并启用了JSON扩展。 我尝试使用这个数组并且运行良好:
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
这是无法工作的数组:我得到的只是一个空字符串,数组是使用PDO获取的数据构建的,后来是array_merge和array_merge_recursively函数。
Array
(
[id] => 32
[numero] => 469
[complemento] => Bloco A
[observacao] => Qualquer coisa � valida aqui!
[clientes] => Array
(
[0] => Array
(
[id] => 237
[id_endereco] => 32
[nome] => Joao Paulo
[data_inicio] => 22/03/2016
[telefones] => Array
(
[donoTelefone] =>
)
[comboTelOwner] => <option value='Joao Paulo'>Joao Paulo</option><option value='Augusta Ap Raymo Longo'>Augusta Ap Raymo Longo</option><option value='Karina Longo'>Karina Longo</option>
)
[1] => Array
(
[id] => 238
[id_endereco] => 32
[nome] => Augusta Ap Raymo Longo
[data_inicio] => 22/03/2016
[telefones] => Array
(
[0] => Array
(
[ddd] => 16
[numero] => 991655725
[id_endereco] => 32
[id_cliente] => 238
[fone_tipo] => 1
)
[donoTelefone] => Augusta Ap Raymo Longo
)
[comboTelOwner] => <option value='Joao Paulo'>Joao Paulo</option><option value='Augusta Ap Raymo Longo' selected='selected'>Augusta Ap Raymo Longo</option><option value='Karina Longo'>Karina Longo</option>
)
[2] => Array
(
[id] => 239
[id_endereco] => 32
[nome] => Karina Longo
[data_inicio] => 22/03/2016
[telefones] => Array
(
[donoTelefone] =>
)
[comboTelOwner] => <option value='Joao Paulo'>Joao Paulo</option><option value='Augusta Ap Raymo Longo'>Augusta Ap Raymo Longo</option><option value='Karina Longo'>Karina Longo</option>
)
)
[cep] => 14076160
[estado] => SP
[cidade] => Ribeir�o Preto
[bairro] => Independ�ncia
[tipo_logradouro] => Rua
[logradouro] => Brigadeiro Tobias de Aguiar
[telefonesComun] => Array
(
[0] => Array
(
[ddd] => 16
[numero] => 30110911
[id_endereco] => 32
[id_cliente] =>
[fone_tipo] => 0
)
[1] => Array
(
[ddd] => 16
[numero] => 36286574
[id_endereco] => 32
[id_cliente] =>
[fone_tipo] => 0
)
)
)
答案 0 :(得分:-1)
对我来说,你的代码不起作用,因为你不使用id,Bloco A等字符串的引号......你还需要在每个元素之间使用逗号。
Discriminator
。