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


PHP JSON::parse方法代碼示例

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


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

示例1: toArray

 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     try {
         return JSON::parse($input = $this->__toString());
     } catch (JSONParseException $e) {
         throw new InvalidException(sprintf('The produced query is not a valid json string : "%s"', $input));
     }
 }
開發者ID:nnexai,項目名稱:Elastica,代碼行數:11,代碼來源:Builder.php

示例2: toArray

 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     try {
         return JSON::parse($this->__toString());
     } catch (JSONParseException $e) {
         throw new InvalidException('The query produced is invalid');
     }
 }
開發者ID:viz,項目名稱:wordpress-fantastic-elasticsearch,代碼行數:11,代碼來源:Builder.php

示例3: testPartialFailure

 /**
  * @group functional
  */
 public function testPartialFailure()
 {
     $this->_checkScriptInlineSetting();
     $client = $this->_getClient();
     $index = $client->getIndex('elastica_partial_failure');
     $index->create(array('index' => array('number_of_shards' => 5, 'number_of_replicas' => 0)), true);
     $type = $index->getType('folks');
     $type->addDocument(new Document('', array('name' => 'ruflin')));
     $type->addDocument(new Document('', array('name' => 'bobrik')));
     $type->addDocument(new Document('', array('name' => 'kimchy')));
     $index->refresh();
     $query = Query::create(array('query' => array('filtered' => array('filter' => array('script' => array('script' => 'doc["undefined"] > 8'))))));
     try {
         $index->search($query);
         $this->fail('PartialShardFailureException should have been thrown');
     } catch (PartialShardFailureException $e) {
         $resultSet = new ResultSet($e->getResponse(), $query);
         $this->assertEquals(0, count($resultSet->getResults()));
         $message = JSON::parse($e->getMessage());
         $this->assertTrue(isset($message['failures']), 'Failures are absent');
         $this->assertGreaterThan(0, count($message['failures']), 'Failures are empty');
     }
 }
開發者ID:makeandship,項目名稱:wordpress-fantastic-elasticsearch,代碼行數:26,代碼來源:PartialShardFailureExceptionTest.php

示例4: getData

 /**
  * Response data array.
  *
  * @return array Response data array
  */
 public function getData()
 {
     if ($this->_response == null) {
         $response = $this->_responseString;
         if ($response === false) {
             $this->_error = true;
         } else {
             try {
                 if ($this->getJsonBigintConversion()) {
                     $response = JSON::parse($response, true, 512, JSON_BIGINT_AS_STRING);
                 } else {
                     $response = JSON::parse($response);
                 }
             } catch (JSONParseException $e) {
                 // leave response as is if parse fails
             }
         }
         if (empty($response)) {
             $response = [];
         }
         if (is_string($response)) {
             $response = ['message' => $response];
         }
         $this->_response = $response;
     }
     return $this->_response;
 }
開發者ID:ruflin,項目名稱:elastica,代碼行數:32,代碼來源:Response.php

示例5: getData

 /**
  * Response data array.
  *
  * @return array Response data array
  */
 public function getData()
 {
     if ($this->_response == null) {
         $response = $this->_responseString;
         if ($response === false) {
             $this->_error = true;
         } else {
             try {
                 $response = JSON::parse($response);
             } catch (JSONParseException $e) {
                 // leave reponse as is if parse fails
             }
         }
         if (empty($response)) {
             $response = array();
         }
         if (is_string($response)) {
             $response = array('message' => $response);
         }
         $this->_response = $response;
     }
     return $this->_response;
 }
開發者ID:MediaWiki-stable,項目名稱:1.26.0,代碼行數:28,代碼來源:Response.php


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