当前位置: 首页>>代码示例>>PHP>>正文


PHP Convert::json2obj方法代码示例

本文整理汇总了PHP中Convert::json2obj方法的典型用法代码示例。如果您正苦于以下问题:PHP Convert::json2obj方法的具体用法?PHP Convert::json2obj怎么用?PHP Convert::json2obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Convert的用法示例。


在下文中一共展示了Convert::json2obj方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testJSON2Obj

 function testJSON2Obj()
 {
     $val = '{"Joe":"Bloggs","Tom":"Jones","My":{"Complicated":"Structure"}}';
     $obj = Convert::json2obj($val);
     $this->assertEquals('Bloggs', $obj->Joe);
     $this->assertEquals('Jones', $obj->Tom);
     $this->assertEquals('Structure', $obj->My->Complicated);
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:8,代码来源:ConvertTest.php

示例2: get

 /**
  * Child classes should call $list = parent::get();
  */
 public static function get()
 {
     $list = parent::get();
     $result = self::service()->request('/RestDataObject');
     if ($result->getStatusCode() == 200) {
         $body = Convert::json2obj($result->getBody());
         if (isset($body->items)) {
             foreach ($body->items as $item) {
                 $list->push(new ExternalRestDataObject((array) $item));
             }
         }
     }
     return $list;
 }
开发者ID:helpfulrobot,项目名称:axyr-silverstripe-externaldata,代码行数:17,代码来源:ExternalRestDataObject.php

示例3: vimeo_video_details

 /**
  * @param $id
  * @return array
  */
 public static function vimeo_video_details($id)
 {
     $url = sprintf('http://vimeo.com/api/v2/video/%s.json', $id);
     $ch = curl_init();
     curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 30));
     $response = Convert::json2obj(curl_exec($ch));
     curl_close($ch);
     $iTime = $response[0]->duration;
     $iHours = intval($iTime / (60 * 60));
     $iMinutes = intval(($iTime - $iHours * 60 * 60) / 60);
     $iSeconds = $iTime - $iHours * 60 * 60 - $iMinutes * 60;
     if ($response) {
         $return = array('title' => $response[0]->title, 'duration' => sprintf("%02d", $iHours) . ':' . sprintf("%02d", $iMinutes) . ':' . sprintf("%02d", $iSeconds));
         return $return;
     }
 }
开发者ID:helpfulrobot,项目名称:mademedia-silverstripe-cloudinary,代码行数:20,代码来源:VimeoVideo.php

示例4: youtube_video_details

 public static function youtube_video_details($id)
 {
     $url = 'https://www.googleapis.com/youtube/v3/videos?';
     $url .= sprintf('key=%s', Config::inst()->get('YoutubeVideo', 'youtube_api_key'));
     $url .= sprintf('&id=%s', $id);
     $url .= '&fields=items(snippet(title),contentDetails(duration))';
     $url .= '&part=snippet,contentDetails';
     $ch = curl_init();
     curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_BINARYTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => 5));
     $response = Convert::json2obj(curl_exec($ch));
     if ($response) {
         $snippet = $response->items[0]->snippet;
         $contentDetails = $response->items[0]->contentDetails;
         curl_close($ch);
         $arrDuration = preg_split('/[^0-9]/', $contentDetails->duration);
         //PT1M26S
         $iHours = isset($arrDuration[2]) ? $arrDuration[2] : 0;
         $iMinutes = isset($arrDuration[3]) ? $arrDuration[3] : 0;
         $iSeconds = isset($arrDuration[4]) ? $arrDuration[4] : 0;
         $return = array('title' => $snippet->title, 'duration' => sprintf("%02d", $iHours) . ':' . sprintf("%02d", $iMinutes) . ':' . sprintf("%02d", $iSeconds));
         return $return;
     }
 }
开发者ID:helpfulrobot,项目名称:mademedia-silverstripe-cloudinary,代码行数:23,代码来源:YoutubeVideo.php

示例5: copyDescriptorToJob

 /**
  * @param QueuedJobDescriptor $jobDescriptor
  * @param QueuedJob $job
  */
 protected function copyDescriptorToJob($jobDescriptor, $job)
 {
     $jobData = null;
     $messages = null;
     // switching to php's serialize methods... not sure why this wasn't done from the start!
     $jobData = @unserialize($jobDescriptor->SavedJobData);
     $messages = @unserialize($jobDescriptor->SavedJobMessages);
     if (!$jobData) {
         // SS's convert:: function doesn't do this detection for us!!
         if (function_exists('json_decode')) {
             $jobData = json_decode($jobDescriptor->SavedJobData);
             $messages = json_decode($jobDescriptor->SavedJobMessages);
         } else {
             $jobData = Convert::json2obj($jobDescriptor->SavedJobData);
             $messages = Convert::json2obj($jobDescriptor->SavedJobMessages);
         }
     }
     $job->setJobData($jobDescriptor->TotalSteps, $jobDescriptor->StepsProcessed, $jobDescriptor->JobStatus == QueuedJob::STATUS_COMPLETE, $jobData, $messages);
 }
开发者ID:natmchugh,项目名称:silverstripe-queuedjobs,代码行数:23,代码来源:QueuedJobService.php

示例6: testHTTPAcceptAndContentType

 public function testHTTPAcceptAndContentType()
 {
     $comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
     $url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
     $headers = array('Accept' => 'application/json');
     $response = Director::test($url, null, null, 'GET', null, $headers);
     $this->assertEquals($response->getStatusCode(), 200);
     // Success
     $obj = Convert::json2obj($response->getBody());
     $this->assertEquals($obj->ID, $comment1->ID);
     $this->assertEquals($response->getHeader('Content-Type'), 'application/json');
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:12,代码来源:RestfulServerTest.php

示例7: validate

 function validate($value)
 {
     if (!$value) {
         return true;
     }
     $this->params[$this->field->getName()] = $value;
     $query = http_build_query($this->params);
     $url = $this->method == 'GET' ? $this->url . '?' . $query : $this->url;
     // If the url is a relative one, use Director::test() to get the response
     if (Director::is_relative_url($url)) {
         $url = Director::makeRelative($url);
         $postVars = $this->method == 'POST' ? $this->params : null;
         $response = Director::test($url, $postVars = null, Controller::curr()->getSession(), $this->method);
         $result = $response->getStatusCode() == 200 ? $response->getBody() : 0;
         // Otherwise CURL to remote url
     } else {
         $ch = curl_init();
         if ($this->method == 'POST') {
             curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
         }
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_USERAGENT, 'ZENVALIDATOR');
         $result = curl_exec($ch);
         curl_close($ch);
     }
     // validate result
     if ($result == '1' || $result == 'true') {
         if ($this->validator == 'reverse') {
             return false;
         } else {
             return true;
         }
     }
     $isJson = is_string($result) && (is_object(json_decode($result)) || is_array(json_decode($result))) ? true : false;
     if ($isJson) {
         $result = Convert::json2obj($result);
         if (isset($result->success)) {
             return true;
         } else {
             if (isset($result->message)) {
                 $this->setMessage($result->message);
             } elseif (isset($result->error)) {
                 $this->setMessage($result->error);
             }
         }
     }
     return false;
 }
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-zenvalidator,代码行数:50,代码来源:ZenValidatorConstraint.php

示例8: receiveChangeset

 public function receiveChangeset($changes, $deletes, $rels)
 {
     Versioned::reading_stage('Stage');
     //		$changes = $changes ? Convert::json2obj($changes) : array();
     //		$deletes = $deletes ? Convert::json2obj($deletes) : array();
     //		$rels = $rels ? Convert::json2obj($rels) : array();
     if ($changes) {
         $all = array_merge($changes, $deletes, $rels);
         $obj = Convert::array2json($all);
         $obj = Convert::json2obj($obj);
         $this->processUpdateData($obj);
         return $all;
     }
     return '';
 }
开发者ID:helpfulrobot,项目名称:silverstripe-syncrotron,代码行数:15,代码来源:SyncrotronService.php

示例9: searchEvents

 public function searchEvents()
 {
     $fields = "?fields=" . implode(',', $this->eventFields);
     $url = $this->endpoint . $this->eventsSearchPath . $fields;
     $client = new RestfulService($url, -1);
     $client = $client->request();
     $response = $client->getBody();
     $events = Convert::json2obj($response);
     return $events;
 }
开发者ID:shoaibali,项目名称:silverstripe-arloapi,代码行数:10,代码来源:EventSearch.php


注:本文中的Convert::json2obj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。