1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace daswork\response;
- use daswork\Response;
- class Json extends Response
- {
- // 输出参数
- protected $options = [
- 'json_encode_param' => JSON_UNESCAPED_UNICODE,
- ];
- protected $contentType = 'application/json';
- /**
- * 处理数据
- * @access protected
- * @param mixed $data 要处理的数据
- * @return mixed
- * @throws \Exception
- */
- protected function output($data)
- {
- try {
- // 返回JSON数据格式到客户端 包含状态信息
- $data = json_encode($data, $this->options['json_encode_param']);
- if ($data === false) {
- throw new \InvalidArgumentException(json_last_error_msg());
- }
- return $data;
- } catch (\Exception $e) {
- if ($e->getPrevious()) {
- throw $e->getPrevious();
- }
- throw $e;
- }
- }
- }
|