本文整理汇总了PHP中Json::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Json::parse方法的具体用法?PHP Json::parse怎么用?PHP Json::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Json
的用法示例。
在下文中一共展示了Json::parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseMustReturnArray
/**
* @test
*/
public function parseMustReturnArray()
{
$expected = ['some' => 1, 'valid' => false, 'payloads' => [1, "10", 1.1, null, true]];
$json = new Json();
$parsed = $json->parse(json_encode($expected));
$this->assertEquals($expected, $parsed);
}
示例2: test_parse_returnsSelf_ifOutputIsValid
/**
* parse() should return true if $output is valid json
*/
public function test_parse_returnsSelf_ifOutputIsValid()
{
$output = '{"foo":"bar"}';
$response = new Json();
$this->assertTrue($response->parse($output));
$this->assertEquals(['foo' => 'bar'], $response->getData());
return;
}
示例3: testParse
public function testParse()
{
$expected = [['name' => 'magento/module-module1', 'dependencies' => [['module' => 'magento/module-module2', 'type' => 'hard'], ['module' => 'magento/module-backend', 'type' => 'soft']]], ['name' => 'magento/module-module2', 'dependencies' => [['module' => 'magento/module-module3', 'type' => 'hard']]]];
$actual = $this->parser->parse(['files_for_parse' => [$this->fixtureDir . 'composer1.json', $this->fixtureDir . 'composer2.json']]);
$this->assertEquals($expected, $actual);
}
示例4: parseDepthError
/**
* @test
* @expectedException \Json\Exception\Decoding
* @expectedExceptionMessage JSON decode failed: Maximum stack depth exceeded (1)
*/
public function parseDepthError()
{
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
$this->markTestSkipped('PHP Version < 5.3.0');
}
// Default max-depth=512 ( x > 512 -> JSON_ERROR_DEPTH )
$json = '[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[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][1]);
$v = array_pop($stack);
$obj[$k] = $v;
}
array_push($stack, (object) array_reverse($obj, true));
break;
case 'Array':
$arr = [];
for ($i = count($tokens) - 2; $i > 0; $i -= 2) {
$v = array_pop($stack);
$arr[] = $v;
}
array_push($stack, array_reverse($arr));
break;
}
});
return $stack[0];
}
}
$j = new Json();
var_dump($j->parse('{"abc":123,"B":["a","b","c"],"c":"\\u795e\\u4ed9"}'));
var_dump($j->parse('{"a":{"V":1},"b":{},"c":[],"d":true}'));
var_dump($j->parse('"abcde"'));
var_dump($j->parse('null'));
var_dump($j->parse('false'));