yii\helpers\BaseJson::decode PHP Метод

decode() публичный статический Метод

Decodes the given JSON string into a PHP data structure.
public static decode ( string $json, boolean $asArray = true ) : mixed
$json string the JSON string to be decoded
$asArray boolean whether to return objects in terms of associative arrays.
Результат mixed the PHP data
    public static function decode($json, $asArray = true)
    {
        if (is_array($json)) {
            throw new InvalidParamException('Invalid JSON data.');
        } elseif ($json === null || $json === '') {
            return null;
        }
        $decode = json_decode((string) $json, $asArray);
        static::handleJsonError(json_last_error());
        return $decode;
    }

Usage Example

Пример #1
0
 public function Resultados()
 {
     $this->CamposO = $this->CamposB;
     //Por ahora son iguales
     //consulta que funciona
     // select idPresta,NombreyApellido from Prestamos left join DatosUser on Prestamos.idUser=DatosUser.IdUser
     //otra consulta que funciona
     // select idPresta,Nombre from Prestamos left join Stock on Prestamos.IdStock=Stock.idStock
     $filtro = BaseJson::decode($this->Filtros);
     $Consulta = (new \yii\db\Query())->select('*')->from($this->Tabla)->where(['like', $this->CamposB, '%' . $this->TBusqueda . '%', false]);
     $Consulta->andWhere($filtro);
     if ($this->OrdenResu != "n") {
         //se ordena
         if ($this->OrdenResu == "d") {
             $Consulta = $Consulta->orderBy([$this->CamposO => SORT_DESC]);
         } else {
             if ($this->OrdenResu == "a") {
                 $Consulta = $Consulta->orderBy([$this->CamposO => SORT_ASC]);
             }
         }
     }
     $this->CantTot = $Consulta->count();
     $Consulta = $Consulta->offset($this->Desplaza)->limit($this->CantReg)->all();
     $this->ResBusca = $Consulta;
     return $this->toArray(['CantTot', 'ResBusca']);
 }
All Usage Examples Of yii\helpers\BaseJson::decode