Here is the json show:

{
  "results": [
    {
      "title": "Conflicting Reports on Iran\u2019s Arrest of a Foreign Woman",
      "multimedia":[
        {
          "caption": "Moktada al-Sadr spoke to thousands of supporters on Saturday, stating conditional support for the Iraqi government."
        }
      ]
    }
 ...]
}

I tried this code, but I can not get the `caption` part. How to do correctly? Thanks.

foreach ($data->results as $result) { 
echo '<p>'.htmlspecialchars($result->title).'</p><br />';
if(!empty($result->multimedia)){
  echo '<p>'.htmlspecialchars($result->multimedia->caption).'</p><br />';
}
}

Recommended Answers

All 2 Replies

Hi,

By the look of your JSON code, multimedia is an array of objects. You could therefore try:

echo $result->multimedia[0]->caption;

Or failing that, use var_dump to view the variable type of multimedia:

var_dump($result->multimedia);

R.

Thanks, robothy, this can work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.