【发布时间】:2026-01-04 14:10:02
【问题描述】:
我想要以下 JSON:
{"success": false,"errors": {"err1": "some error","err2": "another error"}}
我正在使用的代码:
$rs = array("success"=>true);
$rs['errors'][] = array("err1"=>"some error");
$rs['errors'][] = array("err2"=>"another error");
json_encode($rs);
产生以下内容:
{"success":false,"errors":[{"err1":"some error"},{"err2":"another error"}]}
【问题讨论】:
标签: php arrays json formatting