如何使用php过滤和更改json数据的结构

时间:2018-08-30 17:35:50

标签: php json

我有一个类似url的json数据:

{"feed":{"title":"Top Albums",
"id":"https://rss..json",
"author":{"name":"iTunes Store",
"uri":"http://wwww."},
"links":[{"self":"https://r"},{"alternate":"https://"}],
"copyright":"Copyright",
"country":"us",
"icon":"http://itunes.apple.com/favicon.ico",
"updated":"2018-08-29T01:45:02.000-07:00",
"results":[{"artistName":"Travis Scott",
"id":"1421241217",
"releaseDate":"2018-08-03",
"name":"ASTROWORLD",
"kind":"album",
"copyright":"℗ 2018 Epic Records.",
"artistId":"549236696",
"contentAdvisoryRating":"Explicit",
"artistUrl":"https://itunes.apple.com/us/artist/travis-scott/549236696?app=music",
"artworkUrl100":"https://is1-ssl.mzstatic.com/image/thumb/Music118/v4/72/5a/e4/725ae48d-4405-d4bd-0694-91a1b16035d6/886447227169.jpg/200x200bb.png",
"genres":[{"genreId":"18",
"name":"Hip-Hop/Rap",
"url":"https://itunes.apple.com/us/genre/id18"},

我想将其转换为以下格式:

{
    "genre": [
        {
            "genreId": "18",
            "name": "Hip-Hop/Rap",
            "artworkUrl100": "https://is1-ssl.mzstatic.com/image/thumb/Music118/v4/72/5a/e4/725ae48d-4405-d4bd-0694-91a1b16035d6/886447227169.jpg/200x200bb.png"

        }
    ]
}

我有php:

$url = "https://rss.itunes.apple.com/api/v1/us/apple-music/top-albums/all/50/explicit.json";
$json = file_get_contents($url);
$json_data = json_decode($json, true);

0 个答案:

没有答案