如何使用js将JSON对象解析为字符串 [英] How to parse JSON object to a string with js

查看:140
本文介绍了如何使用js将JSON对象解析为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have JSON object and i would like send it as string to php file. How to convert JSON object to string with js/jQuery?

推荐答案

**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'];

这篇关于如何使用js将JSON对象解析为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆