You are here

public function JsonUtility::decodeJsonObject in Feeds extensible parsers 8

Decodes a JSON string into an object or array.

Parameters

string $json: A JSON string.

Return value

object|array A PHP object or array.

Throws

\RuntimeException Thrown if the encoded JSON does not result in an array or object.

File

src/Utility/JsonUtility.php, line 92

Class

JsonUtility
Various helpers for handling JSON.

Namespace

Drupal\feeds_ex\Utility

Code

public function decodeJsonObject($json) {
  $parsed = json_decode($json, FALSE);
  if (!is_array($parsed) && !is_object($parsed)) {
    throw new \RuntimeException($this
      ->t('The JSON is invalid.'));
  }
  return $parsed;
}