解析JSON数据
@param string $result
@param string|null $field
@return bool|array
767230
private function _decode($result, $field = null)
    {
        $this->data = json_decode($result, true);
        if (!empty($this->data['errcode'])) {
            $this->errCode = $this->data['errcode'];
            $this->errMsg = $this->data['errmsg'];
            return false;
        }
        if ($this->data && !is_null($field)) {
            if (isset($this->data[$field])) {
                return $this->data[$field];
            } else {
                return false;
            }
        }
        return $this->data;
    }
671703
public function getValue($value = '', $field = 'id', $fieldOutput = '')
    {
        if (is_array($value) && count($value) > 0) {
            foreach ($value as $f => $v) {
                if (is_array($v)) {
                    $this->db->where($f, $v, self::OPERATOR_IS_IN);
                } else {
                    $this->db->where($f, $v, self::OPERATOR_EQUAL_TO);
                }
            }
        } else {
            $this->db->where($field, $value, self::OPERATOR_EQUAL_TO);
        }
        $result = $this->db->getOne($this->table, $fieldOutput);
        $this->debug->debug(__FUNCTION__, 'GET Result => ' . json_encode($result));
        if (isset($result->$fieldOutput)) {
            return $result->$fieldOutput;
        } else {
            return NULL;
        }
    }
150539
public function row($fields = null, $where = null, $orderBy = null)
    {
        // 按整个SELECT进行查询
        $table = self::selectArray($fields, $where, $orderBy, "1");

        // 如果有,返回第一行
        if ($table) {
            return $table[0];
        }

        return null;
    }
1096318
public function sum($result, $field = 1)
    {
        $field = $this->prepareField($field);

        $this->fields[$result] = ['$sum' => $field];

        return $this;
    }
1281060
public static function instance($result, $client = null)
    {
        if ((array)$result['$data'] === $result['$data']
            && isset($result['$data']['results'])
            && isset($result['$data']['count'])) {
            return new Collection($result, $client);
        }
        
        return new Record($result, $client);
    }
280118
public function toJSON(){
        $outcomeValue = null;
        if($this->defaultValue != ''){
            $outcomeValue = Array($this->defaultValue);
        }else if($this->getAttributeValue('baseType') == 'integer' || $this->getAttributeValue('baseType') == 'float'){
            $outcomeValue = Array(0);
        }else{
            $outcomeValue = null;
        }

        $returnValue = taoQTI_models_classes_Matching_VariableFactory::createJSONVariableFromQTIData(
                        $this->getIdentifier()
                        , $this->getAttributeValue('cardinality')
                        , $this->getAttributeValue('baseType')
                        , $outcomeValue
        );

        return $returnValue;
    }
481795
protected function getFilterFields(&$result) {
        if(!empty($this->_filter)) {
            foreach ($this->_filter as $field=>$filter){
                if(isset($result[$field])) {
                    $fun  =  $filter[1];
                    if(!empty($fun)) {
                        if(isset($filter[2]) && $filter[2]){
                            // 传递整个数据对象作为参数
                            $result[$field]  =  call_user_func($fun,$result);
                        }else{
                            // 传递字段的值作为参数
                            $result[$field]  =  call_user_func($fun,$result[$field]);
                        }
                    }
                }
            }
        }
        return $result;
    }
1205010
final public function queryArrayOne(string $query, string $field = '')
    {
        $result = $this->queryResult($query);
        if (false === $result) {
            return false;
        }

        $return = [];
        $verifiedFieldName = false;
        while ($row = $result->fetchRow()) {
            if ('' === $field) {
                $keys = array_keys($row);
                $field = $keys[0];
                $verifiedFieldName = true;
            }
            if (! $verifiedFieldName) {
                if (! array_key_exists($field, $row)) {
                    return false;
                }
                $verifiedFieldName = true;
            }
            $return[] = $row[$field] ?? null;
        }
        return $return;
    }
390787
protected function processResults($results)
    {
        $json = array();
        foreach($results as $result) {
            $name = $result->{$this->labelField};

            $json[$result->ID] = array(
                'name' => $name,
                'currentString' => $this->getCurrentItemText($result)
            );
        }

        return $json;
    }
1169156
public function jsonSuccess($data = null, $message = null) {
        if (!is_array($message)) {
            $message = ['messages' => $message];
        }
        if ($data instanceof ArrayAble) {
            $data = $data->toArray();
        }
        return $this->json(array_merge(array(
            'code' => 200,
            'status' => __('success'),
            'data' => $data
        ), $message));
    }
721191
private static function convertResult($result)
    {
        if (!is_array($result)) {
            return self::convert($result);
        }

        $results = [];

        foreach ($result as $item) {
            $results[] = self::convert($item);
        }

        return $results;
    }
1157730
public function addSortBy(
        Result $result,
        string $field,
        string $mode
    ): ? string {
        $urlParameters = $this->generateQueryUrlParameters($result);

        if (
            isset($urlParameters['sort_by'][$field]) &&
            $urlParameters['sort_by'][$field] == $mode
        ) {
            return null;
        }

        if (
            !isset($urlParameters['sort_by']) &&
            SortBy::SCORE === [$field => $mode]
        ) {
            return null;
        }

        unset($urlParameters['sort_by']);

        if (SortBy::SCORE !== [$field => $mode]) {
            $urlParameters['sort_by'][$field] = $mode;
        }

        return $this->createUrlByUrlParameters(
            $result,
            $urlParameters
        )['route'];
    }
519238
protected function _fetchFieldList($result, $key = 0)
    {
        $array = array();

        while ($row = $result->fetch_row()) {
            $array[] = $row[(int)$key];
        }

        $result->free();

        return $array;
    }
406970
public function execute(AbstractResult $result)
    {
            $query = http_build_query(
                $this->getParams()
            );

            $url      = $this->apiUrl . $this->getMethod() . '?' . $query;
            $response = $this->downloader->download($url);

            $responseJson = json_decode($response);
            if ( ! $responseJson) {
                throw new RuntimeException('Failed to parse Response. Invalid Json: ' . $response);
            }

            if (isset($responseJson->errno)) {
                throw new ApiException($responseJson->errmsg, $responseJson->errno);
            }
            $result->parseResponse($responseJson);
            $result->setQueryUrl($url);

            return $result;
    }
473735
public function encode($result)
    {
        if ('form' == $this->type) {
            array_walk_recursive($result[0], array($this, 'utf8'));
            
            $response = new SfResponse("<html><body><textarea>".json_encode($result[0])."</textarea></body></html>");            
            $response->headers->set('Content-Type', 'text/html');
            
            return $response;
        } else {
            if ($this->responseEncode){
                // @todo: check utf8 config option from bundle
                array_walk_recursive($result, array($this, 'utf8'));
            }

            $response = new SfResponse(json_encode($result));            
            $response->headers->set('Content-Type', 'application/json');
            
            return $response;
        }
    }
355665
protected function _parseResult($result)
    {
        if (empty($result)) {
            $this->errCode = 'result error';
            $this->errMsg = '解析返回结果失败';
            return false;
        }
        if ($result['return_code'] !== 'SUCCESS') {
            $this->errCode = $result['return_code'];
            $this->errMsg = $result['return_msg'];
            return false;
        }
        if (isset($result['err_code']) && $result['err_code'] !== 'SUCCESS') {
            $this->errMsg = $result['err_code_des'];
            $this->errCode = $result['err_code'];
            return false;
        }
        return $result;
    }
1174500
protected function filterModelEventResults($result)
    {
        if (is_array($result)) {
            $result = array_filter($result, function ($response) {
                return ! is_null($response);
            });
        }

        return $result;
    }