使用 json_encode 将 PHP 数组转换为 JSON 不起作用

Adr*_*ian 1 php json slim php-7

但找不到解决办法。

所以我有一个看起来像这样的数组:

Array(
[0] => Array
    (
        [ID] => 1
        [Vorname] => Fisrtname
        [Nachname] => Lastname
        [Geburtsdatum] => 1990-01-01
        [Email] => test@testmail.com
        [Telefon] => 0511123123
    ))
Run Code Online (Sandbox Code Playgroud)

我想将其转换为 JSON 并将其用作 Slim 的响应。

问题是, echo json_encode(); 并返回 $response->withJson(); 什么也不返回。

正如我所说,我进行了很多搜索,这两种方式是我所能找到的。也许你知道为什么这不起作用。

Art*_*nix 5

关于:json_last_error_msg()

UTF-8 字符格式错误,可能编码不正确

这是一个常见问题。

function utf8convert($mixed, $key = null)
{
    if (is_array($mixed)) {
        foreach ($mixed as $key => $value) {
            $mixed[$key] = utf8convert($value, $key); //recursive
        }
    } elseif (is_string($mixed)) {
        $fixed = mb_convert_encoding($mixed, "UTF-8", "UTF-8");
        return $fixed;
    }
    return $mixed;
}
Run Code Online (Sandbox Code Playgroud)

这几乎就像我刚刚从我之前写的东西中复制了这段代码......哈哈......这在过去给我带来了很多麻烦。所以,曾经做过那件事。