Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我似乎无法让我的 json_encode 包含括号。有什么帮助吗?
我的代码是:
$th = json_encode(array("4" => "four", "8" => "eight")); echo $th;
输出是:
{"4":"four","8":"eight","9":"\n"}
我需要发送到 api 的输出是:
[{"4":"four","8":"eight","9":"\n"}]
如何获取 JSON 数组中的括号?谢谢!
你应该这样做:
$th = json_encode(array(array("4" => "four", "8" => "eight")));
用这个
$th = json_encode(array(array("4" => "four", "8" => "eight", "9" => "\n")));