在javascript中将数组转换为字符串并在php中返回到数组?

在javascript中将数组转换为字符串并在php中返回到数组?

问题描述:

I have an array in javascript, when click a button, I need to print the array as html input value. I did this and it works:

myString = JSON.stringify(results);

After I got the string in php, json_decode($results,true) got null return; How to get the string back to array in php? Or, should I use other ways to convert array to string in javascript at the first place?

update:

This solution works:

$results= preg_replace('/\\\"/',"\"", $results);
$results = json_decode( $results,true );

How ever, I hope there's a better way.

我在javascript中有一个数组,当点击一个按钮时,我需要将数组打印为html输入值。 我做了这个并且它有效: p>

  myString = JSON.stringify(results); 
  code>  pre> 
 
 

我得到之后 php中的字符串, json_decode($ results,true) code>得到null返回; 如何在php中将字符串恢复为数组? 或者,我应该首先使用其他方法在javascript中将数组转换为字符串吗? p>

更新: h2>

此解决方案有效: p >

  $ results = preg_replace('/ \\\“/',”\“”,$ results); 
 $ results = json_decode($ results,true); 
   pre> 
 
 

但是,我希望有更好的方法。 p> div>

Looks like you have magic quotes on. Disable it to stop the massive multitude of backslashes.