【问题标题】:How to parse JSON object to a string with js如何使用 js 将 JSON 对象解析为字符串
【发布时间】:2012-02-22 04:56:00
【问题描述】:

我有 JSON 对象,我想将它作为字符串发送到 php 文件。如何使用 js/jQuery 将 JSON 对象转换为字符串?

【问题讨论】:

    标签: string json parsing


    【解决方案1】:

    使用 JSON.stringify({your object here})

    【讨论】:

      【解决方案2】:

      JSON.stringify(jsonObject) 会给你 jsonObject 转换成一个字符串。它在大多数现代浏览器中本机可用。为了向后兼容,您可以包含JSON-js

      【讨论】:

        【解决方案3】:
        **Check this out it will be helpful**
        
        //index.php
        <script type="text/javascript">
         $(document).ready(function(){
         var json1 = {"test1":"TEST1","test2":"TEST2","test3":"TEST3","test4":"TEST4"};
         str = "data="+JSON.stringify(json1);
        
         $.get('test.php',decodeURI(str),function(html){ alert(html); },"html");
         });
        
        </script>
        
        //test.php
        
        echo $GET['data'];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-03-12
          • 1970-01-01
          • 1970-01-01
          • 2013-10-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多