为了账号安全,请及时绑定邮箱和手机立即绑定

正在回答

2 回答

前端json的代码:

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>json2实战</title>

<script type="text/javascript" src="../json/jquery-1.7.min.js"></script>

</head>

<body>

<script type="text/javascript">

$("document").ready(function(){

var url="shizhan.php";

var data={"do":"first"};

$.getJSON(url,data,function(res){

$("#username").val(res.username);

$("#password").val(res.password);

});

var data={"do":"second"};

$.getJSON(url,data,function(res){

// $("#members").val(res[2].address);

$("#members").val(res.third.members.username);

});

var data={"do":"third"};

$.getJSON(url,data,function(res){

$("#address").val(res.address[2].username);

});

});

</script>


<h2>一维数组巩固练习</h2>

<input type="text" name="username"  id="username"><br>

<input type="password" name="password"  id="password"><br>


<h2>多维数组巩固练习</h2>

<textarea id="members"></textarea>

<textarea id="address"></textarea>

</body>

</html>


服务器端的shizhan.php代码:

    

<?php


// 1'

$member['username']="mukewang";

$member['password']="mukewang";

$do = $_REQUEST['do'];


// 2

$members['1']['username']="慕课网";

$members['1']['password']="mukewang";

$members['2']['username']="gfds";

$members['2']['password']="haha";

$members['2']['address']="朝阳";

$members['third']['members']['username']="第三个用户值";



// 3

class addressClass{

public $address=array();


public function setAddress($array){

$this->address=$array;

}

public function getAddress(){

return $this->address;

}

}


$addressObj=new addressClass();


$addressObj->setAddress($members);

switch($do){

case "first":

echo json_encode($member);

break;

case "second":

echo json_encode($members); //后面的$members其实对应的是上面的二维数组

break;

case "third":

echo json_encode($addressObj);

break;

}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求源代码啊

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信