簡體   English   中英

JSON用PHP解碼字符串(數組數組)特殊字符

[英]JSON decode string in PHP (array of arrays) Special characters

所以在將JSON字符串轉換為PHP數組時遇到了這個問題。 數據是通過HTTP POST發送的,因此我知道可能需要解碼。

任何人都可以深入了解我將如何在PHP中使用json_decode()將此字符串轉換為數組嗎? "[[\\"37\\",\\"text\\",\\"\\\\\\"\\\\\\"\\"],[\\"38\\",\\"text\\",\\"\\\\\\"\\\\\\"\\"],[\\"39\\",\\"text\\",\\"\\\\\\"one word two words. Hello? \\\\\\\\\\\\\\"escape\\\\\\\\\\\\\\" lol\\\\\\"\\"]]"

輸入是:

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

其中userInputtedString是: one word two words. Hello? "escape" lol one word two words. Hello? "escape" lol

^或任何其他Unicode值

似乎是什么問題?

只需使用您提到的json_decode即可。

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

這應該做。

您也可以使用uft8_encode(發送到HTML)和uft8_decode(接收),但方法不正確

在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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM