How to solve JSON_ERROR_UTF8 error in php json_decode?

后端 未结 5 2005
北恋
北恋 2020-11-27 17:46

I am trying this code

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


        
5条回答
  •  無奈伤痛
    2020-11-27 18:27

    I solved adding another 'if' to manage objects in the 'utf8ize' function by @Konstantin (I've not used the other function) :

    function utf8ize($mixed) {
        if (is_array($mixed)) {
            foreach ($mixed as $key => $value) {
                $mixed[$key] = utf8ize($value);
            }
        } else if (is_string ($mixed)) {
            return utf8_encode($mixed);
        } else if (is_object($mixed)) {
            $a = (array)$mixed; // from object to array
            return utf8ize($a);
        }
        return $mixed;
    }
    

提交回复
热议问题