$id,'userName'=>$userName);#把数组序列化echo json_encode($arrayName);?>json输出并解析:
当前位置:   article > 正文

php中json_decode()的使用方法_php的json_decode后多了层array (

php的json_decode后多了层array (

后台json_decode()序列化编码示例:

  1. <?php
  2. $id=$_GET["id"];
  3. $userName=$_GET["userName"];
  4. $arrayName = array('id' => $id,'userName'=>$userName);
  5. #把数组序列化
  6. echo json_encode($arrayName);
  7. ?>

json输出并解析:

  1. <script type="text/javascript" src="https://code.jquery.com/jquery-3.4.0.min.js"></script>
  2. <script>
  3. $(function() {
  4. $.ajax({
  5. url: "index.php",
  6. data: "id=666&userName=admin",
  7. type: "get",
  8. gettype: "json",
  9. success: function(result) {
  10. console.log(result);
  11. var re = eval("(" + result + ")")
  12. console.log(re["id"]);
  13. console.log(re["userName"]);
  14. },
  15. });
  16. });
  17. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/146962?site
推荐阅读