我正在尝试获取特定的 json 响应,但响应中的一个数组正在作为对象传递。
"countries":{"TW":8,"JP":5,"AU":6,"MX":12,"CL":4,"HK":2,"US":14,"AR":4,"ES":1,"BR":1,"MY":9,"IT":12,"DE":1,"GB":1,"PE":6,"TR":1,"KR":3,"IE":1,"CA":2,"FR":1,"VE":2,"IL":1,"PT":1,"NL":1,"PL":1}
但我需要它看起来像这样:
"countries":[["Brazil", 40.5],["US", 30],["Canada", 19.5], ["England", 10]]
如何在 PHP 中为 json_encode 响应构建该数组?
我现在有:
$countries['US']=14;
$countries['CL']=4;
....
然后我将该数组 ($countries) 添加到 $data 数组,这是一个 json 编码
$data['countries'] = $countries;
这给出了我首先发布的结果。但我需要第二种格式。
有人知道我错过了什么吗?
谢谢!