$id,'userName'=>$userName);#把数组序列化echo json_encode($arrayName);?>json输出并解析:
赞
踩
后台json_decode()序列化编码示例:
- <?php
- $id=$_GET["id"];
- $userName=$_GET["userName"];
- $arrayName = array('id' => $id,'userName'=>$userName);
- #把数组序列化
- echo json_encode($arrayName);
- ?>
json输出并解析:
- <script type="text/javascript" src="https://code.jquery.com/jquery-3.4.0.min.js"></script>
- <script>
- $(function() {
- $.ajax({
- url: "index.php",
- data: "id=666&userName=admin",
- type: "get",
- gettype: "json",
- success: function(result) {
- console.log(result);
- var re = eval("(" + result + ")")
- console.log(re["id"]);
- console.log(re["userName"]);
- },
- });
- });
- </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。