測試環境為 CentOS 8 x86_64
JSON 有保留字元,可以直接用以下函數來轉換.
\” Double quote (“)
\b Backslash
\f Formfeed
\n Newline (linefeed)
\r Carriage return
\t Tab
\\ Backslash (\)
\uXXXX UTF-8 bytes for Unicode value XXXX
JSON_QUOTE
範例 : https://mariadb.com/kb/en/json_quote/
MariaDB [(none)]> SELECT JSON_QUOTE('A'), JSON_QUOTE("B"), JSON_QUOTE('"C"'); +-----------------+-----------------+-------------------+ | JSON_QUOTE('A') | JSON_QUOTE("B") | JSON_QUOTE('"C"') | +-----------------+-----------------+-------------------+ | "A" | "B" | "\"C\"" | +-----------------+-----------------+-------------------+ 1 row in set (0.000 sec)
JSON_UNQUOTE
範例 : https://mariadb.com/kb/en/json_unquote/
MariaDB [(none)]> SELECT JSON_UNQUOTE('"Monty"'); +-------------------------+ | JSON_UNQUOTE('"Monty"') | +-------------------------+ | Monty | +-------------------------+ 1 row in set (0.000 sec) MariaDB [(none)]> SELECT JSON_UNQUOTE('\"Monty\"'); +---------------------------+ | JSON_UNQUOTE('\"Monty\"') | +---------------------------+ | Monty | +---------------------------+ 1 row in set (0.000 sec)
沒有解決問題,試試搜尋本站其他內容