Enables amfPHP to receive and reply with JSON This plugin can be deactivated if the project doesn't need to support JSON strings and returned as JSON strings using POST parameters.

You must add the 'application/json' content type, or set it in the headers so that it is recognized as a call to be handled by this plugin. for example: http://yourserver.com/Amfphp/?contentType=application/json

Here is some sample code using Javascript with JQuery:

    var callDataObj = {"serviceName":"PizzaService", "methodName":"getPizza","parameters":[]};
    var callData = JSON.stringify(callDataObj);
    $.post("http://yourserver.com/Amfphp/?contentType=application/json", callData, onSuccess);

Requires at least PHP 5.2.

package | Amfphp_Plugins_Json
author | Yannick DOMINGUEZ

### Methods

## constructor.

    __construct(array $config)

Add filters on the HookManager.

### Parameters

#### $config

`array`

optional key/value pairs in an associative array. Used to override default configuration values.

## deserialize

    deserialize(array $getData, array $postData, string $rawPostData) : string

see | \Amfphp_Core_Common_IDeserializer

### Parameters

#### $getData

`array`

#### $postData

`array`

#### $rawPostData

`string`

### Returns

`string`

## If the content type contains the 'json' string, returns this plugin

    filterHandler(mixed $handler, String $contentType) : \this

### Parameters

#### $handler

`mixed`

null at call in gateway.

#### $contentType

`String`

### Returns

`\this`or null

## Retrieve the serviceName, methodName and parameters from the PHP object representing the JSON string call service

    handleDeserializedRequest(array $deserializedRequest, \Amfphp_Core_Common_ServiceRouter $serviceRouter) : \the

This should not handle exceptions, as this is done separately

see | \Amfphp_Core_Common_IDeserializedRequestHandler

### Parameters

#### $deserializedRequest

`array`

#### $serviceRouter

`\Amfphp_Core_Common_ServiceRouter`

### Returns

`\the`service call response

## don't format; just throw! In this way ajax libs will have their error functions triggered

    handleException(\Exception $exception) : mixed

see | \Amfphp_Core_Common_IExceptionHandler

### Parameters

#### $exception

`\Exception`

### Returns

`mixed`an object describing the error, that will be serialized and sent back to the client

## Encode the PHP object returned from the service call into a JSON string

    serialize(mixed $data) : \the

The return type is noted as a String, but is a binary stream. echo it to the output buffer

see | \Amfphp_Core_Common_ISerializer

### Parameters

#### $data

`mixed`

### Returns

`\the`encoded JSON string sent to JavaScript

### Properties

##

    $returnErrorDetails : boolean

see | \Amfphp_Core_Config::CONFIG_RETURN_ERROR_DETAILS

### Constants

## the content-type string indicating a JSON content

    JSON_CONTENT_TYPE