mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
Documented JSON_FORCE_OBJECT
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@277482 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
515697bc5c
commit
78ecfdf616
2 changed files with 124 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
|
||||
<appendix xml:id="json.constants" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
&reftitle.constants;
|
||||
|
@ -55,6 +55,71 @@
|
|||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<para>
|
||||
The following constants can be combined to form options for
|
||||
<function>json_encode</function>. They are all available as of
|
||||
PHP 5.3.0.
|
||||
</para>
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_HEX_TAG</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
All < and > are converted to \u003C and \u003E.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_HEX_AMP</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
All &s are converted to \u0026.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_HEX_APOS</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
All ' are converted to \u0027.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_HEX_QUOT</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
All " are converted to \u0022.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<constant>JSON_FORCE_OBJECT</constant>
|
||||
(<type>integer</type>)
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Outputs an object rather than an array when a non-associative array is
|
||||
used. Especially useful when the recipient of the output is expecting
|
||||
an object and the array is empty.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</appendix>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.8 $ -->
|
||||
<!-- $Revision: 1.9 $ -->
|
||||
<refentry xml:id="function.json-encode" xmlns="http://docbook.org/ns/docbook">
|
||||
<refnamediv>
|
||||
<refname>json_encode</refname>
|
||||
|
@ -39,10 +39,11 @@
|
|||
<term><parameter>options</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Bitmask consisting of <constant>PHP_JSON_HEX_QUOT</constant>,
|
||||
<constant>PHP_JSON_HEX_TAG</constant>,
|
||||
<constant>PHP_JSON_HEX_AMP</constant>,
|
||||
<constant>PHP_JSON_HEX_APOS</constant>. Defaults to 0.
|
||||
Bitmask consisting of <constant>JSON_HEX_QUOT</constant>,
|
||||
<constant>JSON_HEX_TAG</constant>,
|
||||
<constant>JSON_HEX_AMP</constant>,
|
||||
<constant>JSON_HEX_APOS</constant>,
|
||||
<constant>JSON_FORCE_OBJECT</constant>. Defaults to 0.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -72,7 +73,13 @@
|
|||
<row>
|
||||
<entry>5.2.1</entry>
|
||||
<entry>
|
||||
Added support to JSON encode basic types
|
||||
Added support to JSON encode basic types.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>5.3.0</entry>
|
||||
<entry>
|
||||
The <parameter>options</parameter> parameter was added.
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
|
@ -99,6 +106,51 @@ echo json_encode($arr);
|
|||
<screen>
|
||||
<![CDATA[
|
||||
{"a":1,"b":2,"c":3,"d":4,"e":5}
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<title>A <function>json_encode</function> example showing all the options in action</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$a = array('<foo>',"'bar'",'"baz"','&blong&');
|
||||
|
||||
echo "Normal: ", json_encode($a), "\n";
|
||||
echo "Tags: ", json_encode($a,JSON_HEX_TAG), "\n";
|
||||
echo "Apos: ", json_encode($a,JSON_HEX_APOS), "\n";
|
||||
echo "Quot: ", json_encode($a,JSON_HEX_QUOT), "\n";
|
||||
echo "Amp: ", json_encode($a,JSON_HEX_AMP), "\n";
|
||||
echo "All: ", json_encode($a,JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP), "\n\n";
|
||||
|
||||
$b = array();
|
||||
|
||||
echo "Empty array output as array: ", json_encode($b), "\n";
|
||||
echo "Empty array output as object: ", json_encode($b, JSON_FORCE_OBJECT), "\n\n";
|
||||
|
||||
$c = array(array(1,2,3));
|
||||
|
||||
echo "Non-associative array output as array: ", json_encode($c), "\n";
|
||||
echo "Non-associative array output as object: ", json_encode($c, JSON_FORCE_OBJECT), "\n\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
Normal: ["<foo>","'bar'","\"baz\"","&blong&"]
|
||||
Tags: ["\u003Cfoo\u003E","'bar'","\"baz\"","&blong&"]
|
||||
Apos: ["<foo>","\u0027bar\u0027","\"baz\"","&blong&"]
|
||||
Quot: ["<foo>","'bar'","\u0022baz\u0022","&blong&"]
|
||||
Amp: ["<foo>","'bar'","\"baz\"","\u0026blong\u0026"]
|
||||
All: ["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026"]
|
||||
|
||||
Empty array output as array: []
|
||||
Empty array output as object: {}
|
||||
|
||||
Non-associative array output as array: [[1,2,3]]
|
||||
Non-associative array output as object: {"0":{"0":1,"1":2,"2":3}}
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
|
|
Loading…
Reference in a new issue