复制代码 代码如下:
function jsontest()
{
var json = [{'username':'crystal','userage':'20'},{'username':'candy','userage':'24'}];
alert(json[1].username);
var json2 = [['crystal','20'],['candy','24']];
alert(json2[0][0]);
}
复制代码 代码如下:
$arr = array (
array (
'catid' => '4',
'catname' => '程程',
'meta_title' => '程程博客'
),
array (
'catid' => '6',
'catname' => 'climber',
'meta_title' => '攀登者',
)
);
$jsonstr = json_encode($arr);
echo $jsonstr;
复制代码 代码如下:
$arr = array (
array (
'catid' => '4',
'catname' => '程程',
'meta_title' => '程程博客'
),
array (
'catid' => '6',
'catname' => 'climber',
'meta_title' => '攀登者',
)
);
$jsonstr = json_encode($arr);
-----下面写在php区间之外-----
var jsonstr=< ? = $jsonstr ? >;
复制代码 代码如下:
<SCRIPT type=text/javascript src="php_json.php"></SCRIPT><SCRIPT language=javascript type=text/javascript>
function loadjson(_json)
{
if(_json)
{
for(var i=0;i<_json.length;i++)
{
alert(_json[i].catname);
}
}
}
loadjson(jsonstr)
</SCRIPT>
新闻热点
疑难解答