Как решить ошибку JSON_ERROR_UTF8 в php json_decode?

Я пробую этот код

$json = file_get_contents("http://www.google.com/alerts/preview?q=test&t=7&f=1&l=0&e");
print_r(json_decode(utf8_encode($json), true));

        //////////////

// Define the errors.
$constants = get_defined_constants(true);
$json_errors = array();
foreach ($constants["json"] as $name => $value) {
    if (!strncmp($name, "JSON_ERROR_", 11)) {
        $json_errors[$value] = $name;
    }
}

// Show the errors for different depths.
foreach (range(4, 3, -1) as $depth) {
    var_dump(json_decode($json, true, $depth));
    echo 'Last error: ', $json_errors[json_last_error()], PHP_EOL, PHP_EOL;
}

Я перепробовал множество функций, html_entities_decode, utf8_encode и decode, расшифровывая шестнадцатеричные коды, но я всегда получаю ошибку "JSON_ERROR_UTF8".

Как я могу это решить?

48
задан BeetleJuice 29 July 2017 в 14:29
поделиться