本文整理汇总了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')]);
}