php json_encode 输出json以后jqeruy怎么解析
<?php$arr=array('name'=>"sanzhixiong",'age'=>'22');
echo json_encode($arr);
?>
这是php代码
下面是jquery的代码
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$("#load").click(function(){
$.post(
'http://localhost/json.php',
function(data)
{
alert(data.name);
});
});
});
</script>
</head>
<body>
<input type='button' value='load' id='load'>
<div id="json"></div> 好像就是用eval解析成为一个类啊,对于数组,如果key是数字1、2、3之类的,就被解析为js数组['data1','data2'],数组key是字符串,就转为一个类{key1:value1,key2:value2}。这和js的eval函数一样
eval("({key1:value1,key2:value2})");
页:
[1]