[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> class-json.php (summary)

Converts to and from JSON format. JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. This feature can also be found in  Python. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, TCL, and many others. These properties make JSON an ideal data-interchange language.

Author: Michal Migurski <mike-json@teczno.com>
Author: Matt Knapp
Author: Brett Stimmerman
Copyright: 2005 Michal Migurski
License: http://www.opensource.org/licenses/bsd-license.php
Version: CVS: $Id: JSON.php 305040 2010-11-02 23:19:03Z alan_k $
File Size: 1037 lines (43 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 3 classes

Services_JSON:: (13 methods):
  __construct()
  Services_JSON()
  utf162utf8()
  utf82utf16()
  encode()
  encodeUnsafe()
  _encode()
  name_value()
  reduce_string()
  decode()
  isError()
  strlen8()
  substr8()

Services_JSON_Error:: (4 methods):
  __construct()
  Services_JSON_Error()
  __construct()
  Services_JSON_Error()

Services_JSON_Error:: (4 methods):
  __construct()
  Services_JSON_Error()
  __construct()
  Services_JSON_Error()


Class: Services_JSON  - X-Ref

Converts to and from JSON format.

Brief example of use:

<code>
// create a new instance of Services_JSON
$json = new Services_JSON();

// convert a complex value to JSON notation, and send it to the browser
$value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
$output = $json->encode($value);

print($output);
// prints: ["foo","bar",[1,2,"baz"],[3,[4]]]

// accept incoming POST data, assumed to be in JSON notation
$input = file_get_contents('php://input', 1000000);
$value = $json->decode($input);
</code>
__construct( $use = 0 )   X-Ref
constructs a new JSON instance

param: int     $use    object behavior flags; combine with boolean-OR

Services_JSON( $use = 0 )   X-Ref
PHP4 constructor.


utf162utf8($utf16)   X-Ref
convert a string from one UTF-16 char to one UTF-8 char

Normally should be handled by mb_convert_encoding, but
provides a slower PHP-only method for installations
that lack the multibye string extension.

return: string  UTF-8 character
param: string  $utf16  UTF-16 character

utf82utf16($utf8)   X-Ref
convert a string from one UTF-8 char to one UTF-16 char

Normally should be handled by mb_convert_encoding, but
provides a slower PHP-only method for installations
that lack the multibyte string extension.

return: string  UTF-16 character
param: string  $utf8   UTF-8 character

encode($var)   X-Ref
encodes an arbitrary variable into JSON format (and sends JSON Header)

return: mixed   JSON string representation of input var or an error if a problem occurs
param: mixed   $var    any number, boolean, string, array, or object to be encoded.

encodeUnsafe($var)   X-Ref
encodes an arbitrary variable into JSON format without JSON Header - warning - may allow XSS!!!!)

return: mixed   JSON string representation of input var or an error if a problem occurs
param: mixed   $var    any number, boolean, string, array, or object to be encoded.

_encode($var)   X-Ref
PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format

return: mixed   JSON string representation of input var or an error if a problem occurs
param: mixed   $var    any number, boolean, string, array, or object to be encoded.

name_value($name, $value)   X-Ref
array-walking function for use in generating JSON-formatted name-value pairs

return: string  JSON-formatted name-value pair, like '"name":value'
param: string  $name   name of key to use
param: mixed   $value  reference to an array element to be encoded

reduce_string($str)   X-Ref
reduce a string by removing leading and trailing comments and whitespace

return: string  string value stripped of comments and whitespace
param: $str    string      string value to strip of comments and whitespace

decode($str)   X-Ref
decodes a JSON string into appropriate variable

return: mixed   number, boolean, string, array, or object
param: string  $str    JSON-formatted string

isError($data, $code = null)   X-Ref


strlen8( $str )   X-Ref
Calculates length of string in bytes

return: integer length
param: string

substr8( $string, $start, $length=false )   X-Ref
Returns part of a string, interpreting $start and $length as number of bytes.

return: integer length
param: string
param: integer start
param: integer length

Class: Services_JSON_Error  - X-Ref

__construct($message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null)   X-Ref
PHP5 constructor.


Services_JSON_Error($message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null)   X-Ref
PHP4 constructor.


__construct( $message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null )   X-Ref
PHP5 constructor.


Services_JSON_Error( $message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null )   X-Ref
PHP4 constructor.


Class: Services_JSON_Error  - X-Ref


__construct($message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null)   X-Ref
PHP5 constructor.


Services_JSON_Error($message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null)   X-Ref
PHP4 constructor.


__construct( $message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null )   X-Ref
PHP5 constructor.


Services_JSON_Error( $message = 'unknown error', $code = null,$mode = null, $options = null, $userinfo = null )   X-Ref
PHP4 constructor.




Generated: Tue Dec 24 01:00:02 2024 Cross-referenced by PHPXref 0.7.1