mirror of
https://github.com/php/doc-ja.git
synced 2026-04-27 01:48:12 +02:00
768e8d6ed7
- reference/mbstring/functions/mb-decode-numericentity.xml 1. php/doc-en@4e69a9f2b1 - reference/imap/functions/imap-headerinfo.xml 1. php/doc-en@4e69a9f2b1 - reference/ssh2/functions/ssh2-auth-pubkey-file.xml 1. php/doc-en@74ef2355c5 - reference/ssh2/functions/ssh2-connect.xml 1. php/doc-en@74ef2355c5 - reference/stream/functions/stream-filter-append.xml 1. php/doc-en@a684294e0b - reference/stream/functions/stream-filter-prepend.xml 1. php/doc-en@a684294e0b - reference/filesystem/functions/fgetcsv.xml 1. php/doc-en@e1fd0bef1d 2. php/doc-en@0a3648a718 3. `&warning.csv.escape-parameter;` の重複を削除(既訳のバグ修正) - reference/spl/splfileobject/fgetcsv.xml 1. php/doc-en@e1fd0bef1d 2. php/doc-en@3a89b55d11 3. php/doc-en@0a3648a718 - language/predefined/attributes/nodiscard.xml 1. php/doc-en@30bda33771 - reference/pdo_sqlite/pdo/sqlite/createfunction.xml 1. php/doc-en@28930349ca - reference/math/functions/fmod.xml 1. php/doc-en@54a788ca59 - reference/simplexml/simplexmlelement/addChild.xml 1. php/doc-en@dca2a8354f - reference/json/functions/json-last-error.xml 1. php/doc-en@058ea1e842 - features/commandline.xml 1. php/doc-en@96b10a9885 - appendices/migration85/incompatible.xml 1. php/doc-en@048982b729 2. php/doc-en@f81bbcf9d3 - reference/random/random/randomizer/getfloat.xml 1. php/doc-en@1ada637cc8 2. php/doc-en@423a1da63f - reference/mysqli/mysqli/multi-query.xml 1. php/doc-en@1beae37b69 - reference/image/functions/getimagesize.xml 1. php/doc-en@6bb90d24b2 - reference/curl/functions/curl-close.xml 1. php/doc-en@86c8ebd19e - reference/curl/functions/curl-share-close.xml 1. php/doc-en@29c3d13980 - reference/yaml/functions/yaml-parse-file.xml 1. php/doc-en@132d2a8d63 - reference/mysqli/mysqli/options.xml 1. php/doc-en@e309a62b16 2. MYSQLI_SERVER_PUBLIC_KEY の古い「PHP 5.5.0 以降」テキストを削除(既訳のバグ修正) - appendices/transports.xml 1. php/doc-en@ae90ecc932 - reference/soap/soapserver/addfunction.xml 1. php/doc-en@577239f64b - reference/var/functions/settype.xml 1. php/doc-en@8d49e302b4 - features/http-auth.xml 1. php/doc-en@cd4180557a
256 lines
7.2 KiB
XML
256 lines
7.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 058ea1e8420b9c1b24402af52545e8313428e1d1 Maintainer: takagi Status: ready -->
|
|
<!-- Credits: mumumu -->
|
|
<refentry xml:id="function.json-last-error" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>json_last_error</refname>
|
|
<refpurpose>直近に発生したエラーを返す</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>json_last_error</methodname>
|
|
<void />
|
|
</methodsynopsis>
|
|
<para>
|
|
<constant>JSON_THROW_ON_ERROR</constant> を指定していなかった場合に、
|
|
直近の JSON エンコード/デコード/検証処理中に発生したエラー (もし存在すれば) を返します。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
&no.function.parameters;
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
整数値を返します。これは、次の定数のいずれかとなります。
|
|
</para>
|
|
<table>
|
|
<title>JSON error codes</title>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>定数</entry>
|
|
<entry>意味</entry>
|
|
<entry>使用可能</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_NONE</constant></entry>
|
|
<entry>エラーは発生しませんでした</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_DEPTH</constant></entry>
|
|
<entry>スタックの深さの最大値を超えました</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_STATE_MISMATCH</constant></entry>
|
|
<entry>JSON の形式が無効、あるいは壊れています</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_CTRL_CHAR</constant></entry>
|
|
<entry>制御文字エラー。おそらくエンコーディングが違います</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_SYNTAX</constant></entry>
|
|
<entry>構文エラー</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_UTF8</constant></entry>
|
|
<entry>正しくエンコードされていないなど、不正な形式の UTF-8 文字</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_RECURSION</constant></entry>
|
|
<entry>エンコード対象の値に再帰参照が含まれています</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_INF_OR_NAN</constant></entry>
|
|
<entry>
|
|
エンコード対象の値に
|
|
<link linkend="language.types.float.nan"><constant>NAN</constant></link>
|
|
あるいは <link linkend="function.is-infinite"><constant>INF</constant></link>
|
|
が含まれています。
|
|
</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_UNSUPPORTED_TYPE</constant></entry>
|
|
<entry>エンコード不可能な型の値が渡されました</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_INVALID_PROPERTY_NAME</constant></entry>
|
|
<entry>エンコードできないプロパティ名が渡されました</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_UTF16</constant></entry>
|
|
<entry>おそらく正しくエンコードされていない、不正な UTF-16 文字</entry>
|
|
<entry></entry>
|
|
</row>
|
|
<row>
|
|
<entry><constant>JSON_ERROR_NON_BACKED_ENUM</constant></entry>
|
|
<entry>シリアライズできない、Backed Enum でない値が含まれています。PHP 8.1.0 以降で使用可能。</entry>
|
|
<entry></entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>json_last_error</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// 正しい json 文字列
|
|
$json[] = '{"Organization": "PHP Documentation Team"}';
|
|
|
|
// 間違った json 文字列で、構文エラーとなります
|
|
// ここでは、クォートに " ではなく ' を使用しています
|
|
$json[] = "{'Organization': 'PHP Documentation Team'}";
|
|
|
|
|
|
foreach ($json as $string) {
|
|
echo 'Decoding: ' . $string;
|
|
json_decode($string);
|
|
|
|
switch (json_last_error()) {
|
|
case JSON_ERROR_NONE:
|
|
echo ' - No errors';
|
|
break;
|
|
case JSON_ERROR_DEPTH:
|
|
echo ' - Maximum stack depth exceeded';
|
|
break;
|
|
case JSON_ERROR_STATE_MISMATCH:
|
|
echo ' - Underflow or the modes mismatch';
|
|
break;
|
|
case JSON_ERROR_CTRL_CHAR:
|
|
echo ' - Unexpected control character found';
|
|
break;
|
|
case JSON_ERROR_SYNTAX:
|
|
echo ' - Syntax error, malformed JSON';
|
|
break;
|
|
case JSON_ERROR_UTF8:
|
|
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
|
|
break;
|
|
default:
|
|
echo ' - Unknown error';
|
|
break;
|
|
}
|
|
|
|
echo PHP_EOL;
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Decoding: {"Organization": "PHP Documentation Team"} - No errors
|
|
Decoding: {'Organization': 'PHP Documentation Team'} - Syntax error, malformed JSON
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>json_last_error</function> と <function>json_encode</function> の組み合わせ</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// 無効な UTF8 シーケンス
|
|
$text = "\xB1\x31";
|
|
|
|
$json = json_encode($text);
|
|
$error = json_last_error();
|
|
|
|
var_dump($json, $error === JSON_ERROR_UTF8);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
string(4) "null"
|
|
bool(true)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>json_last_error</function> と <constant>JSON_THROW_ON_ERROR</constant> の組み合わせ</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// JSON_ERROR_UTF8 が発生する、不正なUTF8シーケンス
|
|
json_encode("\xB1\x31");
|
|
|
|
// 次の文字列は、JSON error が発生しない
|
|
json_encode('okay', JSON_THROW_ON_ERROR);
|
|
|
|
// グローバルなエラー状態は、直前の json_encode() によって変更されない
|
|
var_dump(json_last_error() === JSON_ERROR_UTF8);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
bool(true)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>json_last_error_msg</function></member>
|
|
<member><function>json_decode</function></member>
|
|
<member><function>json_encode</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|