0

所以我找到了一些关于如何做到这一点的答案,但它们都没有真正起作用,即 json_decode()。这就是我所做的:

  1. 我创建了 js 对象/数组
  2. 然后我通过Ext.Ajax.Requestas将它传递给 php 文件JSON.stringify(js object)
  3. 现在在我的 php 中,我看到该字符串的结果如下:["James;","George;"]

我想把它作为一个像 (James, George) 这样的 php 数组。有什么简单的方法可以做到这一点,还是我必须手动移除不必要的部分?

4

2 回答 2

1

好的,我在这个问题上看了一会儿,终于得到了答案。

在 php 中,我需要添加json_decode(stripslashes($scenarios)), where $scenarios = ["James;","George;"].

代码:($scenarios 是通过 Ajax 使用 JSON.stringify(js object) 从 js 文件发送的)

<?php

$scenarios = empty($_GET['scenarios']) ? false : $_GET['scenarios'];
// more code for validation

$arr = json_decode(stripslashes($scenarios));
?>

现在 $arr 将成为常规的 php 数组。

于 2013-06-06T20:06:15.940 回答
0

使用html_entity_decode函数

于 2013-06-06T19:45:04.173 回答