在PHP中从JSON获取值

在PHP中从JSON获取值,php,json,Php,Json,我试图使用PHP从JSON提要中获取一些值。由于某种原因,我已经尝试了很多小时,但都没有成功 我试图实现的是从json提要中获取每个项目的标题,如下所示: stdClass Object ( [rss] => stdClass Object ( [@attributes] => stdClass Object ( [version] => 2.0 ) [ch

我试图使用PHP从JSON提要中获取一些值。由于某种原因,我已经尝试了很多小时,但都没有成功

我试图实现的是从json提要中获取每个项目的标题,如下所示:

stdClass Object
(
[rss] => stdClass Object
    (
        [@attributes] => stdClass Object
            (
                [version] => 2.0
            )

        [channel] => stdClass Object
            (
                [title] => PR.com Press Releases
                [link] => http://www.PR.com/
                [description] => Latest news releases from PR.com
                [ttl] => 60
                [image] => stdClass Object
                    (
                        [title] => PR.com Press Releases
                        [link] => http://www.PR.com/
                        [url] => http://www.PR.com/images/logo_white.jpg
                    )

                [item] => Array
                    (
                        [0] => stdClass Object
                            (
                                [title] => Nation’s Top Online Medical Weight Loss Provider Now www.hCGTreatments.com
                                [link] => http://www.pr.com/press-release/669077
                                [guid] => http://www.pr.com/press-release/669077
                                [description] => <p><em>With an improved protocol and advancements in technology, HCGTreatments.com has become one of the most reliable names in online weight loss.</em></p>
                                [pubDate] => Sat, 30 Apr 2016 07:00:00 +0000
                                [dc_creator] => Diet Doc
                                [dc_language] => en-us
                                [dc_format] => text/html
                                [dc_identifier] => http://www.pr.com/press-release/669077
                            )

                        [1] => stdClass Object
                            (
                                [title] => Sentynl Therapeutics, Inc. Launches Its Commercial Organization
                                [link] => http://www.pr.com/press-release/669136
                                [guid] => http://www.pr.com/press-release/669136
                                [description] => <p>Sentynl Therapeutics, Inc. Launches Its Commercial Organization</p>
                                [pubDate] => Sat, 30 Apr 2016 07:00:00 +0000
                                [dc_creator] => Sentynl Therapeutics, Inc.
                                [dc_language] => en-us
                                [dc_format] => text/html
                                [dc_identifier] => http://www.pr.com/press-release/669136
                            )

                        [2] => stdClass Object
                            (
                                [title] => Professional of the Year 2015, Bruce H. Levin, is Now a Lifetime VIP in America’s Registry of Outstanding Professionals
                                [link] => http://www.pr.com/press-release/664848
                                [guid] => http://www.pr.com/press-release/664848
                                [description] => <p>Professional of the Year 2015, Bruce H. Levin, is Now a Lifetime VIP in America’s Registry of Outstanding Professionals</p>
                                [pubDate] => Sat, 30 Apr 2016 07:00:00 +0000
                                [dc_creator] => America's Registry of Outstanding Professionals
                                [dc_language] => en-us
                                [dc_format] => text/html
                                [dc_identifier] => http://www.pr.com/press-release/664848
                            )

                    )

            )

    )

)
$url = "http://example.com/file.json"; // just an example
$json_file = file_get_contents("$url");

$json = json_decode($json_file, true);

foreach($rss->$item as $mydata)
{
echo $mydata->title . "\n";
} 
我尝试了数百种变体,但都没有得到所有的标题

也许有人能给我指出正确的方向


谢谢:)

尝试获取这样的对象

$url = "http://example.com/file.json"; // just an example
$json_file = file_get_contents("$url");

$json = json_decode($json_file, true);

foreach($rss->$item as $mydata->$value)
{
echo $value->title . "\n";
} 

试着得到这样的物体

$url = "http://example.com/file.json"; // just an example
$json_file = file_get_contents("$url");

$json = json_decode($json_file, true);

foreach($rss->$item as $mydata->$value)
{
echo $value->title . "\n";
} 
$json=json\u解码($json\u文件,true)
这会给你一个关联数组,我不知道
$rss
是从哪里来的?echo print\r($json,true);在使用foreach语句之前,首先查看结果。然后修改
$json=json\u decode($json\u file,true)的$mydata->标题可能重复
这会给你一个关联数组,我不知道
$rss
是从哪里来的?echo print\r($json,true);在使用foreach语句之前,首先查看结果。然后修改您的$mydata->titlePossible duplicate