json_decode()期望参数1是给定的字符串数组

时间:2018-05-27 01:10:51

标签: php json

我尝试将json_decode更改为json_encode,但错误转为为foreach()提供的无效参数。

public function getCloudsList(){
        $clouds = array();
        try {
            $apiManager =  new ApiManager();
            $oauthManager = new OAuthManager();
            $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId();
            $response = json_decode($apiManager->getCloudsList());
            foreach ($response as $cloud) {
                $isActive = false;
                $token = $oauthManager->getTokenUserCloud($user, $cloud);
                if ($token) {
                    if (strlen($token->getTsecret()) > 0) {
                        $isActive = true;
                        $tokenAux = new stdClass();
                        $tokenAux->key = $token->getTKey();
                        $tokenAux->secret =$token->getTSecret();
                        $_SESSION['access_token_' . $cloud . '_v2'] = $tokenAux;
                    }
                }
                array_push($clouds, array("name" => $cloud, "isActive" => $isActive));
            }
        } catch (Exception $e){
            throw new Exception($e->getMessage());
        }
        return $clouds;
    }

0 个答案:

没有答案