Forum und email

json_encode

(PHP 5 >= 5.2.0, PECL json:1.2.0-1.2.1)

json_encode — Returns the JSON representation of a value

Popis

string json_encode ( mixed $value )

Returns a string containing the JSON representation of value .

Parametre

value

The value being encoded. Can be any type except a resource.

This function only works with UTF-8 encoded data.

Vrátené hodnoty

Returns a JSON encoded string on success.

ChangeLog

Verzia Popis
5.2.1 Added support to JSON encode basic types

Príklady

Example#1 A json_encode() example

<?php
$arr 
= array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);

echo 
json_encode($arr);
?>

Výstup horeuvedeného príkladu bude:

{"a":1,"b":2,"c":3,"d":4,"e":5}

Tiež pozri