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


PHP Json::fromXml方法代码示例

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


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

示例1: __construct

 public function __construct($xml)
 {
     $json = Json::fromXml($xml);
     $array = Json::decode($json, true);
     $this->code = $array['code'];
     $this->reference = $array['reference'];
     $this->type = $array['type'];
     $this->status = $array['status'];
     $this->cancellationSource = $array['cancellationSource'];
 }
开发者ID:adelarcubs,项目名称:pagseguro_zend,代码行数:10,代码来源:Transaction.php

示例2: unserialize

 /**
  * Deserialize XML to PHP value
  *
  * @param  string $xml
  * @return mixed
  * @throws Exception\InvalidArgumentException
  * @throws Exception\RuntimeException
  */
 public function unserialize($xml)
 {
     try {
         $json = Json::fromXml($xml);
         $unserialized = Json::decode($json, Json::TYPE_OBJECT);
     } catch (\InvalidArgumentException $e) {
         throw new Exception\InvalidArgumentException('Unserialization failed: ' . $e->getMessage(), 0, $e);
     } catch (\Exception $e) {
         throw new Exception\RuntimeException('Unserialization failed: ' . $e->getMessage(), 0, $e);
     }
     return $unserialized;
 }
开发者ID:zpetr,项目名称:apigility-xmlnegotiation,代码行数:20,代码来源:Xml.php

示例3: testNestingDepthIsHandledProperlyWhenNestingDepthDoesNotExceedMaximum

 /**
  * @group ZF-11385
  * @dataProvider providerNestingDepthIsHandledProperly
  */
 public function testNestingDepthIsHandledProperlyWhenNestingDepthDoesNotExceedMaximum($xmlStringContents)
 {
     try {
         Json\Json::$maxRecursionDepthAllowed = 25;
         $jsonString = Json\Json::fromXml($xmlStringContents, true);
         $jsonArray = Json\Json::decode($jsonString, Json\Json::TYPE_ARRAY);
         $this->assertNotNull($jsonArray, "JSON decode result is NULL");
         $this->assertSame('A', $jsonArray['response']['message_type']['defaults']['close_rules']['after_responses']);
     } catch (Zend\Json\Exception\RecursionException $ex) {
         $this->fail('Zend_Json::fromXml does not implement recursion check properly');
     }
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:16,代码来源:JsonXmlTest.php

示例4: testNestingDepthIsHandledProperlyWhenNestingDepthDoesNotExceedMaximum

 /**
  * @group ZF-11385
  * @dataProvider providerNestingDepthIsHandledProperly
  */
 public function testNestingDepthIsHandledProperlyWhenNestingDepthDoesNotExceedMaximum($xmlStringContents)
 {
     Json\Json::$maxRecursionDepthAllowed = 25;
     $jsonString = Json\Json::fromXml($xmlStringContents, true);
     $jsonArray = Json\Json::decode($jsonString, Json\Json::TYPE_ARRAY);
     $this->assertNotNull($jsonArray, "JSON decode result is NULL");
     $this->assertSame('A', $jsonArray['response']['message_type']['defaults']['close_rules']['after_responses']);
 }
开发者ID:nieldm,项目名称:zf2,代码行数:12,代码来源:JsonXmlTest.php

示例5: parseXmlResponse

 protected function parseXmlResponse(Response $response)
 {
     $responseText = $response->getBody();
     if (!$responseText) {
         return;
     }
     $data = Json::decode(Json::fromXml($responseText), Json::TYPE_ARRAY);
     return $data;
 }
开发者ID:ahyswang,项目名称:eva-engine,代码行数:9,代码来源:AbstractAdapter.php

示例6: testUsingXML6

    /**
     * xml2json Test 6
     * It tests the conversion of demo application xml into JSON format.
     *
     * XML characteristic to be tested: XML containing a large CDATA.
     *
     */
    public function testUsingXML6()
    {
        // Set the XML contents that will be tested here.
        $xmlStringContents = <<<EOT
<?xml version="1.0"?>
<demo>
    <application>
        <name>Killer Demo</name>
    </application>

    <author>
        <name>John Doe</name>
    </author>

    <platform>
        <name>LAMP</name>
    </platform>

    <framework>
        <name>Zend</name>
    </framework>

    <language>
        <name>PHP</name>
    </language>

    <listing>
        <code>
            <![CDATA[
/*
It may not be a syntactically valid PHP code.
It is used here just to illustrate the CDATA feature of Zend_Xml2JSON
*/
<?php
include 'example.php';
new SimpleXMLElement();
echo(getMovies()->movie[0]->characters->addChild('character'));
getMovies()->movie[0]->characters->character->addChild('name', "Mr. Parser");
getMovies()->movie[0]->characters->character->addChild('actor', "John Doe");
// Add it as a child element.
getMovies()->movie[0]->addChild('rating', 'PG');
getMovies()->movie[0]->rating->addAttribute("type", 'mpaa');
echo getMovies()->asXML();
?>
            ]]>
        </code>
    </listing>
</demo>

EOT;

        // There are not going to be any XML attributes in this test XML.
        // Hence, set the flag to ignore XML attributes.
        $ignoreXmlAttributes = true;
        $jsonContents = "";

        // Convert XML to JSON now.
        // fromXml function simply takes a String containing XML contents as input.
        $jsonContents = Json\Json::fromXml($xmlStringContents, $ignoreXmlAttributes);

        // Convert the JSON string into a PHP array.
        $phpArray = Json\Json::decode($jsonContents, Json\Json::TYPE_ARRAY);
        // Test if it is not a NULL object.
        $this->assertNotNull($phpArray, "JSON result for XML input 6 is NULL");
        // Test for one of the expected fields in the JSON result.
        $this->assertContains("Zend", $phpArray['demo']['framework']['name'], "The framework name field converted from XML input 6 is not correct");
        // Test for one of the expected CDATA fields in the JSON result.
        $this->assertContains('echo getMovies()->asXML();', $phpArray['demo']['listing']['code'], "The CDATA code converted from XML input 6 is not correct");
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:76,代码来源:JsonXmlTest.php


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