0

我似乎无法让我的 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 数组中的括号?谢谢!

4

2 回答 2

3

你应该这样做:

$th = json_encode(array(array("4" => "four", "8" => "eight")));
于 2012-11-05T23:10:50.440 回答
0

用这个

$th = json_encode(array(array("4" => "four", "8" => "eight", "9" => "\n")));
于 2012-11-06T03:13:16.880 回答