為數組里的每個元素進行urlencode() 轉碼 后再用json_encode() 轉為json即可, 解碼使用json_decode()
示例:
foreach ( $result as $keys => $value )
//包含中文的二維數組$result轉json,數組內部元素一一使用urlencode轉換即可保證中文不亂碼 { foreach($value as $key=>$column){ $testJSON[$keys][$key] = urlencode ( $column ); } } var_dump( json_encode ( $testJSON ));//轉為json $result = urldecode ( json_encode ( $testJSON ) );//轉回數組
