获取POST过来的二进制数据,与手机端交互

@param bool $formatJson 获取的数据是否为json并格式化为数组
@param string $jsonField 获取json格式化为数组的字段多维数组用.分隔  如top.son.son2

@return bool|mixed|null|string
5669
public static function getBinaryData($formatJson = false, $jsonField = '')
    {
        if (isset($GLOBALS['HTTP_RAW_POST_DATA']) && !empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
            $data = $GLOBALS['HTTP_RAW_POST_DATA'];
        } else {
            $data = file_get_contents('php://input');
        }
        if ($formatJson) {
            $data = json_decode($data, true);
            $jsonField && $data = Cml::doteToArr($jsonField, $data);
        }
        return $data;
    }
623138
public static function groupResponse($json)
    {
        $fields = Deserialize::_fromJson($json);
        return Deserialize::_groupResponseFromFields($json, $fields);
    }
1338730
public function json($pretty=FALSE) {
		if($pretty) {
			$sorted = $this->payload;
			$this->sortRecursive($sorted);
			return json_encode($sorted, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
		} else {
			return json_encode($this->payload);
		}
	}
121771
function check_json(string $json, bool $return_error = false)
  {
    json_decode($json);
    $error = json_last_error();
    if ( $error === JSON_ERROR_NONE ){
      return true;
    }
    if ( !$return_error ){
      return false;
    }
    switch ( $error ) {
      case JSON_ERROR_DEPTH:
        return _('Maximum stack depth exceeded');
      case JSON_ERROR_STATE_MISMATCH:
        return _('State mismatch (invalid or malformed JSON)');
      case JSON_ERROR_CTRL_CHAR:
        return _('Unexpected control character found');
      case JSON_ERROR_SYNTAX:
        return _('Syntax error, malformed JSON');
      case JSON_ERROR_UTF8:
        return _('Malformed UTF-8 characters, possibly incorrectly encoded');
      default:
        return _('Unknown error');
    }
  }
145406
public function asJson(bool $pretty = false): string
    {
        $response = $this->compile();

        $options = 0;
        if ($pretty) {
            $options = \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT;
        }

        $json = json_encode($response, $options);

        if (false === $json) {
            throw JsonEncodeException::fromJsonError(\json_last_error(), $response);
        }

        return $json;
    }
1335772
public function isJson() {
        if (!$this->endsWith('}') && !$this->endsWith(']')) {
            return false;
        }

        return !is_null(json_decode($this->str));
    }
858544
public static function isJSON($json)
    {
        if ($json === '[]' || $json === '{}') {
            return true;
        } else if (is_array($json)) {
            return false;
        }

        return static::decode($json) != null;
    }
221763
public static function isJson($string){

        if(!is_string($string)) return false;

        if(empty($string)) return false;

        json_decode($string);
        return (json_last_error() == JSON_ERROR_NONE);
    }
5147
public static function retJSON($response = null, $prettyPrint = false)
    {
        $options = $prettyPrint ? JSON_PRETTY_PRINT : 0;

        return json_encode($response, $options);
    }
640119
public static function parseJson($jsonString)
    {
        $jsonObj = json_decode($jsonString, true);
        $jsonCheck = json_last_error();
        if ($jsonObj === null && $jsonCheck !== JSON_ERROR_NONE) {
            $msg = "Invalid json string: $jsonString -- "
                . "json_last_error() returns $jsonCheck";
            throw new Error\ParseException($msg);
        }
        return self::constructFrom($jsonObj);
    }
822505
public function check($form, $jsonInput = false)
    {
        $result = [];
        $errors = [];
        $inputs = [];

        if (is_array($form)) {
            $fields = $form;
        } else {
            $conditions = Cms::config('validation.'.$form);
            $fields = $conditions;
        }

        if (!is_array($fields)) {
            $fields = [$fields];
        }

        $validationRules = $validationInputs = [];

        foreach ($fields as $key => $value) {
            if (isset($fields[$key])) {
                $inputs[$key] = $this->getInput($key, $jsonInput);
                $validationInputs[$key] = $this->getInput($key, $jsonInput);
                $validationRules[$key] = $fields[$key];
            }
        }

        $validation = Validator::make($validationInputs, $validationRules);

        if ($validation->fails()) {
            $errors = $validation->messages();
        }

        if (!$jsonInput) {
            $result['redirect'] = Redirect::back()->with('errors', $errors)->with('inputs', $this->inputsArray($jsonInput));
        }

        if (!empty($errors)) {
            $result['errors'] = $errors;
        } else {
            $result['errors'] = false;
        }

        $result['inputs'] = $this->inputsArray($jsonInput);

        return $result;
    }
756008
public function readJson($check_header = true, $override = false)
	{
		if( !is_null($this->from_json) && !$override )
		{
			return $this->from_json;
		}

		// set false json reader
		$this->from_json = false;

		if( $check_header )
		{
			$type = $this->server->getIs("CONTENT_TYPE") ? $this->server->get("CONTENT_TYPE") : $this->server->getOr("HTTP_ACCEPT", '');
			if( ! preg_match('/(?:application|text)\/json(?:$|;| )/', $type) )
			{
				return false;
			}
		}

		$body = $this->body();
		if( strlen($body) && ( $body[0] === "{" || $body[0] === "[" ) )
		{
			$this->params_post = new Collection( Json::parse($body, true) );
			$this->body = '';
			$this->from_json = true;
		}

		return $this->from_json;
	}
1272112
public static function decode(string $json)
    {
        $value = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

        if ($error = json_last_error()) {
            throw new JsonException(json_last_error_msg(), $error);
        }

        return $value;
    }
375927
public function format_json($field)
    {
        if (!is_scalar($this->current_row[$field])) {
            $this->current_row[$field] = json_encode($this->current_row[$field]);
        }
    }
853717
public static function invoke($jsonString, $returnNode = false)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');

        $jsonString = mb_convert_encoding($jsonString, 'UTF-8', mb_detect_encoding($jsonString));

        $jsonDecode = json_decode($jsonString, false);
        $lastError = json_last_error();

        if (JSON_ERROR_NONE === $lastError)
        {
            $ul = $dom->createElement('ul');
            $ul->setAttribute('class', 'json-list');
            $dom->appendChild($ul);

            if ($jsonDecode instanceof \stdClass)
                self::objectOutput($jsonDecode, $dom, $ul);
            else if (is_array($jsonDecode))
                self::arrayOutput($jsonDecode, $dom, $ul);

            if ($returnNode)
                return $dom;

            return static::saveHTMLExact($dom, $ul);
        }

        throw new \DomainException(sprintf(
            'Could not convert input to HTML: "%s"',
            JsonErrorHelper::invoke(true, $lastError)
        ));
    }
117944
public function decode($json)
    {
        $data = json_decode($json, true);
        if ($data === null && json_last_error() != JSON_ERROR_NONE) {
            throw new JsonSerializerException('Invalid JSON to unserialize.');
        }

        if (!is_array($data)) {
            throw new JsonSerializerException('Given JSON cannot represent an object.');
        }

        if (mb_strpos($json, $this->encodingAnnotation) !== false) {
            $data = $this->decodeNonUtf8FromUtf8($data);
        }

        return $data;
    }
727590
protected function json( $value )
	{
		if( !is_string( $value ) || '' === $value ){
			return false;
		}
		json_decode( $value );
		return (json_last_error() === JSON_ERROR_NONE);
	}