http://itpro.nikkeibp.co.jp/article/COLUMN/20070307/264116/
基本的にUTF-8で処理することを前提としているので、
その他の文字コードを利用する場合は
mb_convert_variables('UTF-8', 'SHIFT-JIS', $arr);
のように文字コードを変更する
1 |
<?php ini_set('error_reporting', E_ALL); ini_set('display_errors', '1'); require_once "JSON.php"; $arr = array( array( "name" => "アシアル", "url" => "http://www.asial.co.jp/" ), array( "name" => "PHPプロ", "url" => "http://www.phppro.jp/" ) ); // $arr["test"] = "あああ"; $json = new Services_JSON; mb_convert_variables('UTF-8', 'SHIFT-JIS', $arr); $encode = $json->encode($arr); // header("Content-Type: text/html; charset=shift-jis"); // echo $encode; ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis"> <!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8">--> <title>テスト</title> <script language="javascript"> function test(){ var get_json = eval( <?php echo( $encode) ?> ); // alert(get_json[0]["name"]); alert(get_json["test"]); } </script> </head> <body> テスト <input type="button" value="test" onClick="javascript:test();"> </body> </html> |
[通知用URL]
Tweet
最終更新時間:2013年02月04日 20時44分55秒