我似乎无法让我的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数组中的括号? 谢谢!
答案 0 :(得分:3)
你应该这样做:
$th = json_encode(array(array("4" => "four", "8" => "eight")));
答案 1 :(得分:0)
使用此
$th = json_encode(array(array("4" => "four", "8" => "eight", "9" => "\n")));