0

Below is my json file in which i need to access certain parts of it. I am trying to loop through the json file and then echo the content selected.

{
  "Userprofile": [
    {
      "profile": {
        "profile_type": "Customer",
        "users": [
          {
            "external_urls": {
              "ThereWebsite": "https://www.example.com/58lV9VcRSjABbAbfWS6skp"
            },
            "id": "58lV9VcRSjABbAbfWS6skp",
            "name": "Example Name",
            "type": "Customer",
            "uri": "www.test.com"
          }
        ],
        "available_markets": [
          "AD",
          "AR",
          "AT",
          "AU",
          "AD"
        ],
        "external_urls": {
          "spotify": "https://www.test.com"
        },
        "href": "https://www.test.com",
        "id": "5uU2uM1RGHfzlA12opjqol",
        "images": [
          {
            "height": 637,
            "url": "https://i.scdn.co/image/03e6e600fb3b9c4c6ef0df6b0d287d0e7d18d799",
            "width": 640
          },
          {
            "height": 299,
            "url": "https://i.scdn.co/image/c6f43aeb1beba2eb216a175be31e4ce0fb7fe094",
            "width": 300
          },
          {
            "height": 64,
            "url": "https://i.scdn.co/image/28e08d0ce4a749f33e04590eb6225d30985c004f",
            "width": 64
          }
        ]
}

how do I loop through using php to access this data and display it on my webpage

current using

"images": [
          {
            "height": 637,
            "url": "https://i.scdn.co/image/03e6e600fb3b9c4c6ef0df6b0d287d0e7d18d799",
            "width": 640
          },
          {
            "height": 299,
            "url": "https://i.scdn.co/image/c6f43aeb1beba2eb216a175be31e4ce0fb7fe094",
            "width": 300
          },
          {
            "height": 64,
            "url": "https://i.scdn.co/image/28e08d0ce4a749f33e04590eb6225d30985c004f",
            "width": 64
          }
        ]

an example of which I used for a previous json file however it was a lot smaller file.

   foreach($result as $album)
            {
                foreach($album['artists'] as $artist)
                {
                  echo "Name: " . $artist['name'] . ", URL: " . $artist['external_urls']['spotify']   .  "\r\n";

                }
         }
John
  • 171
  • 3
  • 19
  • It's a bit unclear what you are asking. Is the problem how to get the images array from the decoded jsonObject? Please also show how you decoded the json (with or without the array flag). – Jeff Nov 16 '18 at 01:00
  • `$images = $decodedJson['Userprofile']['profile']['images']` would be how to access the images array. Then you can iterate over that: `foreach($images as $image) {}` – Jeff Nov 16 '18 at 01:02

0 Answers0