如何解析JSON对象与js的字符串

问题描述:

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

使用JSON.stringify({你的对象这里})

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

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