0

I have the following json array, I am trying to retrive the values but it does not work

 => Array (
    [url] => http://chrome.blogspot.com/feeds/posts/default
    [title] => <b>Google</b> Chrome <b>Blog</b>

This is the code I am using in php to retrive the values

$json = json_decode($res, true);

echo $json['url'];

Can some one help on this.

2 Answers 2

2

Its any array of arrays

echo $json[0]['url'];

From the comment

Array ( [responseData] =>
            Array ( [query] => Official Google Blogs 
                              [entries] => Array ( [0]=>


 echo $json['responseData']['entries'][0]['url'];

To display all the values you have to loop through each entries

foreach($json['responseData']['entries'] as $data)
{
  echo $data['url'];
}
Sign up to request clarification or add additional context in comments.

6 Comments

I tryed this also but it gives following error PHP Notice: Undefined offset: 0 in /home/manoj/php/curl.php on line 10
You can't be certain that the index is actually 0, it could be a different integer, or it could be a string key.
This is the json I have Array ( [responseData] => Array ( [query] => Official Google Blogs [entries] => Array ( [0] => Array ( [url] => googleblog.blogspot.com/feeds/posts/default [title] => <b>Official Blog</b> [contentSnippet] => 4 days ago <b>...</b> <b>Official</b> weblog, with news of new products, events and glimpses of life inside <br> <b>Google</b>.
echo $json['responseData']['entries'][0]['url'];
This does not work, it gave the following error PHP Notice: Undefined index: entries in /home/manoj/php/curl.php on line 11
|
0

Please debug the $json via print_r($json); and then check current status of array and their indexes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.