1
0
mirror of https://github.com/php/doc-ja.git synced 2026-04-23 07:58:01 +02:00
Files
archived-doc-ja/reference/json/functions/json-last-error.xml
T
TAKAGI Masahiro cace0f7401 Sync with en
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@330256 c90b9560-bf6c-de11-be94-00142212c4b1
2013-05-16 23:29:46 +00:00

194 lines
5.0 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: f621ea25b00e93f645e6e663ce448cafdd85f45f Maintainer: takagi Status: ready -->
<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>
直近の 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>PHP 5.3.3</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>
</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
-->