データベースから読み取り、データをjson形式で返すAPIで遊んでいます。
phpMyAdminでは文は完璧です(私はutf8_generalを使用してcsvを入力しました)。例:
A line that uses 'r and special chars etc
しかし、jsonをエコーすると、次のようになります。
A line that uses ///\\/\/\/r and special chars etc
最初にnullオブジェクトを取り戻したので、次を使用しました。
mysql_set_charset('utf8', $link);
しかし、私はまだ破損したデータを取り戻します。
アップデート:
いくつかの詳細:
mysql_set_charset('utf8',$link);
/* grab the posts from the db */
$query = "SELECT * FROM huren WHERE 1";
$result = mysql_query($query,$link) or die('Errant query: '.$query);
// check row count
$amount = mysql_num_rows($result);
/* create one master array of the records */
$houses = array();
if(mysql_num_rows($result)) {
while($post = mysql_fetch_assoc($result)) {
$houses[] = $post;
}
}
/* output in necessary format */
header('Content-type: application/json');
$changed_json= str_replace('\\/', '/',json_encode(array('House'=>$houses)));
echo str_replace('\\\\', '\\',$changed_json);