I
I
iSize1ce2015-09-06 00:10:23
PHP
iSize1ce, 2015-09-06 00:10:23

How to parse JSON in a loop?

{
   "serial": {
      "title_ru": "Во все тяжкие",
      "title_en": "Breaking Bad",
      "token": "ac68ccf3ec244f3f6980816b9a27cc36",
      "type": "serial",
      "kinopoisk_id": 404900,
      "translator": "LostFilm",
      "translator_id": 2,
      "last_episode_time": "2014-03-26 22:29:34",
      "iframe_url": "http://moonwalk.cc/serial/ac68ccf3ec244f3f6980816b9a27cc36/iframe"
   },
   "season_episodes_count": [
      {
         "season_number": 1,
         "episodes_count": 7
      },
      {
         "season_number": 2,
         "episodes_count": 13
      },
      {
         "season_number": 3,
         "episodes_count": 13
      },
      {
         "season_number": 4,
         "episodes_count": 13
      },
      {
         "season_number": 5,
         "episodes_count": 16
      }
   ]
}

How to parse season_episodes_count in a loop? The number of values ​​can be different.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Defman21, 2015-09-06
@Pavell18RUS

It's not entirely clear what you wanted there, but this is how you can run through the season_episodes_count.

$json = json_decode("тут жсон", true);
foreach ($json['season_episodes_count'] as $season) {
    // $season -> ['season_number' => X, 'episodes_count' => Y]
    // делай с этим что хочешь
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question