public static function FeedImport::processJSON in Feed Import 7.2
Process JSON.
Parameters
array $feed: Feed info array
Return value
array An array of objects
File
- ./
feed_import.inc.php, line 1520 - Feed import class for parsing and processing content.
Class
- FeedImport
- @file Feed import class for parsing and processing content.
Code
public static function processJSON(array $feed) {
try {
$json = json_decode(file_get_contents($feed['url']));
} catch (Exception $e) {
return NULL;
}
if (empty($json)) {
return NULL;
}
$xml = new self::$simpleXMLElement($feed['xpath']['#settings']['xml_properties']);
// Convert object to xml.
if (is_array($json)) {
// If the json is an array then make it object.
$json = (object) array(
'item' => $json,
);
}
self::json2xml($json, $xml);
unset($json);
$xml = $xml
->xpath($feed['xpath']['#root']);
if (empty($xml)) {
return NULL;
}
foreach ($xml as &$item) {
// Set this item value to entity, so all entities will be in $xml at end!
$item = self::createEntity($feed, $item);
}
unset($feed);
// Return created entities.
return $xml;
}