Php Yi2-如何强制响应JSON格式化程序使用对象而不是数组?
我知道我可以设置Php Yi2-如何强制响应JSON格式化程序使用对象而不是数组?,php,json,yii,yii2,httpresponse,Php,Json,Yii,Yii2,Httpresponse,我知道我可以设置Yii::$app->response->format=\Yii\web\response::format\u JSON,但是我如何设置JSON编码标志JSON\u FORCE\u OBJECT,这样所有数组都将被编码为对象呢?好吧,这并不难: Yii::$app->response->formatters[\Yii\web\response::FORMAT\u JSON]=[ 'class'=>'yii\web\jsonresponseformter', 'encodeOpti
Yii::$app->response->format=\Yii\web\response::format\u JSON
,但是我如何设置JSON编码标志JSON\u FORCE\u OBJECT
,这样所有数组都将被编码为对象呢?好吧,这并不难:
Yii::$app->response->formatters[\Yii\web\response::FORMAT\u JSON]=[
'class'=>'yii\web\jsonresponseformter',
'encodeOptions'=>JSON\u FORCE\u对象,
];
甚至作为一个班轮:
Yii::$app->response->formatters[\yii\web\Response::FORMAT_JSON]['encodeOptions'] = JSON_FORCE_OBJECT;