0

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 />';
}
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by cj333
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.