當前位置: 首頁>>代碼示例>>PHP>>正文


PHP JsonHelper::toJson方法代碼示例

本文整理匯總了PHP中JsonHelper::toJson方法的典型用法代碼示例。如果您正苦於以下問題:PHP JsonHelper::toJson方法的具體用法?PHP JsonHelper::toJson怎麽用?PHP JsonHelper::toJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在JsonHelper的用法示例。


在下文中一共展示了JsonHelper::toJson方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: sendMessage

 /**
  * Sends a message.
  * @param mixed $message
  * @return MessageResponse|HttpResponse|null
  * @throws ErrorException
  */
 public function sendMessage($message)
 {
     $resource = "/messages/";
     if (is_null($message)) {
         throw new ErrorException("Parameter 'message' cannot be null");
     } elseif (!$message instanceof Message && !is_array($message)) {
         throw new ErrorException("Parameter 'message' must be an instance of Message or an array");
     }
     try {
         $params = array();
         $params = is_array($message) ? $message : json_decode(JsonHelper::toJson($message), true);
         $params["Direction"] = MessageDirection::OUT;
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_CREATED) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new MessageResponse($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
開發者ID:fredrickabayie,項目名稱:MyBankWeb,代碼行數:34,代碼來源:MessagingApi.php

示例2: addContactGroup

 /**
  * Creates a new Contact Group
  * @param mixed $group The contact group data. It can be an associative array or an instance of ContactGroup
  * @return HttpResponse|null|ContactGroup
  * @throws ErrorException
  */
 public function addContactGroup($group)
 {
     $resource = "/contacts/groups/";
     if (is_null($group)) {
         throw new ErrorException("Parameter 'group' cannot be null");
     }
     if (!is_string($group) || !$group instanceof ContactGroup || !is_array($group)) {
         throw new ErrorException("Parameter 'group' must be of type ContactGroup or an array or a string");
     }
     try {
         $params = array();
         if (is_string($group)) {
             $params["Name"] = $group;
         } else {
             $params = is_array($group) ? $group : json_decode(JsonHelper::toJson($group), true);
         }
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_CREATED) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new ContactGroup($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (\Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
開發者ID:natino45,項目名稱:smsghapi-php,代碼行數:38,代碼來源:ContactApi.php

示例3: updateSupportTicket

 /**
  * Replies to a Support Ticket
  * @param integer $ticketId
  * @param mixed $request
  * @return HttpResponse|null|Ticket
  * @throws \ErrorException
  */
 public function updateSupportTicket($ticketId, $request)
 {
     $resource = "/tickets/";
     if (is_null($ticketId)) {
         throw new \ErrorException("Parameter 'ticketId' cannot be null");
     } elseif (!is_int($ticketId)) {
         throw new \ErrorException("Parameter 'ticketId' must be an integer");
     }
     if (is_null($request)) {
         throw new \ErrorException("Parameter 'request' cannot be null");
     } elseif (!$request instanceof TicketResponse || !is_array($request)) {
         throw new \ErrorException("Parameter 'request' must be of type TicketResponse or an array");
     }
     try {
         $params = array();
         $params = is_array($request) ? $request : json_decode(JsonHelper::toJson($request), true);
         $response = $this->httpClient->put($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new Ticket($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (\Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
開發者ID:natino45,項目名稱:smsghapi-php,代碼行數:39,代碼來源:SupportApi.php

示例4: updateContentMedia

 /**
  * Updates the details of an existing content media.
  * @param UUID $mediaId The content media
  * @param MediaInfo $mediaInfo The content media details
  * @return HttpResponse|ContentMedia|null
  * @throws ErrorException
  */
 public function updateContentMedia($mediaId, $mediaInfo = null)
 {
     $resource = "/media/";
     if (is_null($mediaId)) {
         throw new ErrorException("Parameter 'mediaId' cannot be null");
     } elseif (!CommonUtil::is_uuid($mediaId)) {
         throw new ErrorException("Parameter 'mediaId' must be a valid UUID");
     }
     if (!is_null($mediaInfo) && !$mediaInfo instanceof MediaInfo) {
         throw new ErrorException("Parameter 'mediaInfo' cannot be null and must be an instance of MediaInfo.");
     }
     try {
         $resource .= $mediaId;
         // Set the mediainfo data
         $params["ContentName"] = $mediaInfo->contentName;
         $params["LibraryId"] = $mediaInfo->libraryId;
         $params["DestinationFolder"] = $mediaInfo->destinationFolder;
         $params["Preference"] = $mediaInfo->preference;
         $params["Width"] = $mediaInfo->width;
         $params["Height"] = $mediaInfo->height;
         $params["DrmProtect"] = $mediaInfo->drmProtect;
         $params["Streamable"] = $mediaInfo->streamable;
         $params["DisplayText"] = $mediaInfo->displayText;
         $params["ContentText"] = $mediaInfo->contentText;
         $params["Tags"] = "";
         // set the medainfo tags
         if (!is_null($mediaInfo->tags) && is_array($mediaInfo->tags) && count($mediaInfo->tags) > 0) {
             $params["Tags"] = JsonHelper::toJson($mediaInfo->tags);
         }
         $response = $this->httpClient->put($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new ContentMedia($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         $ex->getTraceAsString();
     }
     return null;
 }
開發者ID:fredrickabayie,項目名稱:MyBankWeb,代碼行數:52,代碼來源:ContentApi.php

示例5: updateAccountSettings

 /**
  * Update Account Settings or Preferences and returns the updated preference object.
  * In case of errors an error is triggered
  * @param mixed $request Preference Object to update
  * @return Setting|HttpResponse|null Updated preference
  * @throws ErrorException
  */
 public function updateAccountSettings($request)
 {
     $resource = "/account/settings/";
     if (is_null($request)) {
         throw new ErrorException("Parameter 'preference' cannot be null");
     } elseif (!is_array($request) || !$request instanceof Setting) {
         throw new ErrorException("Parameter 'request' must be an array");
     }
     try {
         $params = array();
         $params = is_array($request) ? $request : json_decode(JsonHelper::toJson($request), true);
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new Setting($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
開發者ID:fredrickabayie,項目名稱:MyBankWeb,代碼行數:34,代碼來源:AccountApi.php


注:本文中的JsonHelper::toJson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。