Values in UTF-8 being encoded as NULL in JSON

后端 未结 5 2070
鱼传尺愫
鱼传尺愫 2021-02-08 19:39

I have a set of keywords that are passed through via JSON from a DB (encoded UTF-8), some of which may have special characters like é, è, ç, etc. This is used as part of an auto

5条回答
  •  庸人自扰
    2021-02-08 20:32

    Try sending your array through this function before doing json_encode():

    = '30') {
            return false;
        }
    
        /* step through inArray */
        foreach($inArray as $key=>$val) {
            if(is_array($val)) {
                /* recurse on array elements */
                $newArray[$key] = utf8json($inArray);
            } else {
                /* encode string values */
                $newArray[$key] = utf8_encode($val);
            }
        }
    
        /* return utf8 encoded array */
        return $newArray;
    }
    ?>
    

    Taken from comment on phpnet @ http://php.net/manual/en/function.json-encode.php.

    The function basically loops though array elements, perhaps you did your utf-8 encode on the array itself?

提交回复
热议问题