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


PHP Json::encode方法代碼示例

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


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

示例1: testComplex

 public function testComplex()
 {
     $data = ['a' => 1, 'b' => [1, 2, 4], 'c' => 3, 'd' => 4, 'e' => 5];
     $json = Json::encode($data);
     $map = Json::toMap($json);
     $this->assertTrue($map instanceof Map);
     $this->assertTrue($map->get('b') instanceof ArrayList);
     $this->assertEquals($data, $map->toArray());
 }
開發者ID:phootwork,項目名稱:json,代碼行數:9,代碼來源:CollectionTest.php

示例2: updateExtensions

 protected function updateExtensions(Package &$model, KeekoPackageSchema $pkg)
 {
     // remove all existing extensions from this package first
     ExtensionQuery::create()->filterByPackage($model)->delete();
     // add them one by one
     foreach ($pkg->getAllExtensions() as $key => $exts) {
         foreach ($exts as $data) {
             $ext = new Extension();
             $ext->setKey($key);
             $ext->setData(Json::encode($data, Json::UNESCAPED_SLASHES));
             $ext->setPackage($model);
             $ext->save();
         }
     }
 }
開發者ID:keeko,項目名稱:framework,代碼行數:15,代碼來源:AbstractPackageInstaller.php

示例3: run

 /**
  * Automatically generated run method
  *
  * @param Request $request
  * @return Response
  */
 public function run(Request $request)
 {
     $url = str_replace($request->getRequestUri(), '', $request->getUri());
     $baseurl = str_replace($url, '', $this->getBaseUrl());
     $sport = SportQuery::create()->findOneById($this->getParam('sport'));
     if (!$sport->getIsDefault()) {
         $baseurl .= '/' . $sport->getSlug();
     }
     // load assets
     $page = $this->getServiceContainer()->getKernel()->getApplication()->getPage();
     $repo = $this->getServiceContainer()->getResourceRepository();
     $page->addStyles($repo->find('/gossi/trixionary-client/public/app/assets/*.css')->getPaths());
     $page->addScripts($repo->find('/gossi/trixionary-client/public/app/assets/vendor-*.js')->getPaths());
     $page->addScripts($repo->find('/gossi/trixionary-client/public/app/assets/trixionary-*.js')->getPaths());
     // set configuration
     $prefs = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences();
     $config = ['modulePrefix' => 'trixionary', 'environment' => 'production', 'rootURL' => $baseurl, 'locationType' => 'auto', 'APP' => ['name' => 'trixionary', 'version' => '0.0.0+0d11dfba'], 'keeko' => ['api' => $prefs->getApiUrl(), 'trixionary' => ['sportId' => $sport->getId(), 'slug' => ['skill' => $sport->getSkillSlug(), 'group' => $sport->getGroupSlug(), 'object' => $sport->getObjectSlug()]]]];
     $meta = new Meta();
     $meta->setName('trixionary/config/environment');
     $meta->setContent(rawurlencode(Json::encode($config)));
     $page->addMeta($meta);
     return $this->responder->run($request, new Blank(['sport' => $sport]));
 }
開發者ID:gossi,項目名稱:trixionary-client,代碼行數:29,代碼來源:SportAction.php

示例4: testExtendedPackage

 public function testExtendedPackage()
 {
     $package = PackageSchema::fromFile(__DIR__ . '/fixture/extended.json');
     $json = Json::encode($package->toArray(), Json::PRETTY_PRINT | Json::UNESCAPED_SLASHES);
     $expected = file_get_contents(__DIR__ . '/fixture/extended.json');
     $this->assertEquals($expected, $json);
 }
開發者ID:keeko,項目名稱:framework,代碼行數:7,代碼來源:ComposerSchemaTest.php

示例5: testEncodeBroken

 /**
  * @expectedException \phootwork\json\JsonException
  * @expectedExceptionCode \phootwork\json\Json::ERROR_UTF8
  */
 public function testEncodeBroken()
 {
     Json::encode([pack("H*", 'c32e')]);
 }
開發者ID:phootwork,項目名稱:json,代碼行數:8,代碼來源:JsonTest.php


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