JSON output modifications

I have the following code, I need to only get [list] from JSON response ... not everything

<?php


error_reporting(E_ALL);

$urls = array(
    'https://api.dailymotion.com/user/cricshare/videos?page=1&limit=100',
    'https://api.dailymotion.com/user/cricshare/videos?page=2&limit=100',
    'https://api.dailymotion.com/user/cricshare/videos?page=3&limit=100'
);

$sets = array();
foreach ($urls as $url) {
    $json   = file_get_contents($url);
    $data   = json_decode($json);
    $sets[] = $data;
}

$new = json_encode($sets, JSON_PRETTY_PRINT);
echo '<pre>';
echo $new;

?>

Open in new window


Here is the output:

http://joomclan.com/json2db/json_read.php

Open in new window

LVL 5
CalmSoulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
This does not seem very efficient, but it appears to work.  You get a merged array of the lists of objects.

<?php // demo/temp_calmsoul.php

/**
 * See http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28634264.html
 */
error_reporting(E_ALL);
echo '<pre>';

$urls = array(
    'https://api.dailymotion.com/user/cricshare/videos?page=1&limit=100',
    'https://api.dailymotion.com/user/cricshare/videos?page=2&limit=100',
    'https://api.dailymotion.com/user/cricshare/videos?page=3&limit=100',
);

$sets = array();
foreach ($urls as $url) {
    $json   = file_get_contents($url);
    $sets[] = json_decode($json);
}
$new = json_encode($sets);
$obj = json_decode($new);

$lists = [];
foreach ($obj as $unit_response)
{
    $lists = array_merge($lists, $unit_response->list);
}
$out = json_encode($lists, JSON_PRETTY_PRINT);

$cnt = count($lists);
echo PHP_EOL . "THERE ARE $cnt ELEMENTS IN THIS ARRAY";
print_r($out);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CalmSoulAuthor Commented:
Thanks - that worked
0
Ray PaseurCommented:
Thanks for the points - it's a great question, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.