0

So I have this issue when converting a JSON string to a PHP array. The data is sent via HTTP POST so I'm aware there may be some decoding needed.

Could anyone lay an insight on how I would use json_decode() in PHP to convert this string to an array? "[[\"37\",\"text\",\"\\\"\\\"\"],[\"38\",\"text\",\"\\\"\\\"\"],[\"39\",\"text\",\"\\\"one word two words. Hello? \\\\\\\"escape\\\\\\\" lol\\\"\"]]"

The input was:

[
    ["37", "text", ""],
    ["38", "text", ""],
    ["39", "text", userInputtedString]
]

Where userInputtedString is: one word two words. Hello? "escape" lol

^ Or any other Unicode values

4

3 回答 3

2

在 json_decode 之前使用 utf8_encode

$str = "[[\"37\",\"text\",\"\\\"\\\"\"],[\"38\",\"text\",\"\\\"\\\"\"],[\"39\",\"text\",\"\\\"one word two words. Hello? \\\\\\\"escape\\\\\\\" lol\\\"\"]]";
$str = utf8_encode($str);
$str = json_decode($str,JSON_UNESCAPED_SLASHES);
于 2016-06-07T12:00:44.937 回答
1

似乎是什么问题?

像你提到的那样简单地使用 json_decode 。

$ans = json_decode($_POST["name-of-var"]);

这应该这样做。

于 2016-06-07T11:40:47.500 回答
1

您也可以使用 uft8_encode(发送到 HTML)和 uft8_decode(接收)但不是正确的方式

于 2016-06-07T11:45:35.583 回答