当前位置: 首页>>代码示例>>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;未经允许,请勿转载。