atest.html文件中输入
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function JSON_test()
{
var user = {
name:'大都会',
email:'jxin@sina.com',
password:'232555'
}
var json_string = JSON.stringify(user);
document.getElementById('txt_json').value=json_string;
alert("点击确定后将提交表单");
submit();
}
</script>
</head>
<body>
<form method="post" action="json_encode.php" οnsubmit="JSON_test();return flase;">
<p><input type="hidden" name="txt_json" id="txt_json" />
<input type="submit" name="sssxx" id="ddddxx" value="fff" />
</p>
</form>
</body>
</html>
json_encode.php文件中输入
<?php
header('Content-Type: text/html; charset=utf-8');
$json_string = $_POST["txt_json"];
//echo $json_string;
if(ini_get("magic_quotes_gpc")=="1")
{
$json_string=stripslashes($json_string);
}
$user = json_decode($json_string);
echo var_dump($user);
echo '<br /><br /><br /><br />';
echo $user->name.'<br />';
echo $user->email.'<br />';
echo $user->password.'<br />';
?>