Table of Contents

json_encode

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

JSON encode an array into a string, with optional method

Description

string json_encode ( array $array [, int $method ] )

Return a string containing the JSON1) encoded representation of an array

Parameters

$array: An array to parse

$method: Optional, output the JSON code string to represent an object or an array:

Return Values

JSON encoded string

Example

<pre><?
  $arr=array();
  $arr['a']=1;
  $arr['b']=2;
  $arr['c']=3;
  print(json_encode($arr)."\r\n");   // encode as an object (default method)
  print(json_encode($arr,0)."\r\n"); // encode as an object
  print(json_encode($arr,1)."\r\n"); // encode as an array
?></pre>

The above example will output:

"$arr":{"a":1,"b":2,"c":3}
"$arr":{"a":1,"b":2,"c":3}
"$arr":{1,2,3]

See Also

array() - Create an array, with optional values

explode() - Turn a string into an array

implode() - Turn an array into a string

uPHP Variable Types and Limits

1)
JSON stands for “JavaScript Object Notation.” It is a lightweight format that is used for data interchanging. It is based on a subset of the JavaScript language (the way objects are built in JavaScript).