本文整理匯總了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());
}
示例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();
}
}
}
示例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]));
}
示例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);
}
示例5: testEncodeBroken
/**
* @expectedException \phootwork\json\JsonException
* @expectedExceptionCode \phootwork\json\Json::ERROR_UTF8
*/
public function testEncodeBroken()
{
Json::encode([pack("H*", 'c32e')]);
}