2017-04-16 145 views
0

兩個問題:
1.我使用yii2的post方法獲取由Angularjs中ngResource前端發送的json數據。我配置yii2如下:如何通過yii2獲取json數據

'parsers' => [ 
    'application/json' => 'yii\web\JsonParser', 
    'text/json' => 'yii\web\JsonParser', 
] 

但是當我使用$ =後的Yii :: $ APP->請求 - >後()來獲取數據這是行不通的。此外,數據不會被序列化。
2.I配置yii2

'response' => [ 
     'formatters' => [ 
      \yii\web\Response::FORMAT_JSON => [ 
       'class' => 'yii\web\JsonResponseFormatter', 
       'prettyPrint' => YII_DEBUG, 
      ] 
     ] 
    ], 

當我發現這是不同於

​​

返回之前一定的價值。前者不會將數據轉換爲json格式。我不知道爲什麼?

回答

0

1.我強制contentTye應用程序/ x-www-form-urlencoded; charset = utf-8,它太愚蠢了。 2.格式與格式不同。