zoukankan      html  css  js  c++  java
  • JSON.stringify 使用注意事项

     

    JSON.stringify() 后端接收返回null

    当前端内容过于复杂时,需要对内容进行 转码,否则后端接收不到(json_decode 返回null

    例如:

     // 组装图片数据

                        var json;

                        var voucherImg = new Array;

                        $("#voucher_upload_img").children('div').each(function(index, val){

                                var img = $(this).children('img');

                                voucherImg[index] = {};

                                voucherImg[index]['name'] = img.attr('title');

                                voucherImg[index]['size'] = img.attr('data-size');

                                voucherImg[index]['content'] = img.attr('src');

                        })

                        voucherImgString = encodeURIComponent(JSON.stringify(voucherImg));

                        data.field['voucherImgString'] = voucherImgString;

                    }

     

    encodeURIComponent();对前端内容进行编码;

    后端接收:

                $voucher = json_decode(urldecode( $request->param('voucherImgString')),true);//超标凭证

     

    这样就不会 造成数据json_decode() 的时候返回null 了

     

    文章来源:刘俊涛的博客 欢迎关注公众号、留言、评论,一起学习。

    __________________________________________________________________________________

    若有帮助到您,欢迎点击推荐,您的支持是对我坚持最好的肯定(*^_^*)

  • 相关阅读:
    推荐有关微信开发的十个开源项目
    curl 常见错误码
    mysql修改root密码
    BAT批处理之文件与文件夹操作代码(附xcopy命令详解)
    UE4 Pak包加载
    libcurl 文件上传
    win7右键在目录当前打开命令cmd窗口
    SQLiteDeveloper破解
    Excel替换应用
    解决局域网2级路由互相连接共享的问题
  • 原文地址:https://www.cnblogs.com/lovebing/p/15684010.html
Copyright © 2011-2022 走看看