本文整理汇总了PHP中FormatJson::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP FormatJson::parse方法的具体用法?PHP FormatJson::parse怎么用?PHP FormatJson::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormatJson
的用法示例。
在下文中一共展示了FormatJson::parse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getData
/**
* Decodes the JSON string.
*
* Note that this parses it without casting objects to associative arrays.
* Objects and arrays are kept as distinguishable types in the PHP values.
*
* @return Status
*/
public function getData()
{
if ($this->jsonParse === null) {
$this->jsonParse = FormatJson::parse($this->getNativeData());
}
return $this->jsonParse;
}
示例2: jsonDecode
public function jsonDecode($s, $flags)
{
$this->checkType('mw.text.jsonDecode', 1, $s, 'string');
$this->checkTypeOptional('mw.text.jsonDecode', 2, $flags, 'number', 0);
$flags = (int) $flags;
$opts = FormatJson::FORCE_ASSOC;
if ($flags & self::JSON_TRY_FIXING) {
$opts |= FormatJson::TRY_FIXING;
}
$status = FormatJson::parse($s, $opts);
if (!$status->isOk()) {
throw new Scribunto_LuaError('mw.text.jsonDecode: ' . $status->getMessage()->text());
}
$val = $status->getValue();
if (!($flags & self::JSON_PRESERVE_KEYS) && is_array($val)) {
$val = self::reindexArrays($val, false);
}
return array($val);
}
示例3: testParseErrors
/**
* @dataProvider provideParseErrors
* @param mixed $value
*/
public function testParseErrors($value)
{
$st = FormatJson::parse($value);
$this->assertType('Status', $st);
$this->assertFalse($st->isOK());
}
示例4: testParseStripComments
/**
* @covers FormatJson::parse
* @covers FormatJson::stripComments
* @dataProvider provideParseStripComments
* @param string $json
* @param mixed $expect
*/
public function testParseStripComments($json, $expect)
{
$st = FormatJson::parse($json, FormatJson::STRIP_COMMENTS);
$this->assertType('Status', $st);
$this->assertTrue($st->isGood());
$this->assertEquals($expect, $st->getValue());
}
示例5: getReport
/**
* Get the report from post body and turn into associative array.
*
* @return Array
*/
private function getReport()
{
$postBody = $this->getRequest()->getRawInput();
if (strlen($postBody) > self::MAX_POST_SIZE) {
// paranoia, already checked content-length earlier.
$this->error('toobig', __METHOD__);
}
$status = FormatJson::parse($postBody, FormatJson::FORCE_ASSOC);
if (!$status->isGood()) {
list($code, ) = $this->getErrorFromStatus($status);
$this->error($code, __METHOD__);
}
$report = $status->getValue();
if (!isset($report['csp-report'])) {
$this->error('missingkey', __METHOD__);
}
return $report['csp-report'];
}
示例6: toArr
private function toArr($message, $params, $dictByDefault = false)
{
if (is_string($params) && $params) {
$p = $params;
if ($p[0] !== '[' && $p[0] !== '{') {
$p = $dictByDefault ? '{' . $params . '}' : "[{$params}]";
}
$st = FormatJson::parse($p, FormatJson::FORCE_ASSOC);
$this->assertTrue($st->isOK(), "{$message}: invalid JSON value {$params}");
$params = $st->getValue();
}
return $params;
}