在php中解析stdClass对象数据

发布于 2024-08-06 23:52:34 字数 4104 浏览 3 评论 0原文

我是一名中级 PHP 程序员,但正在努力处理 Google AJAX API 的输出。我将以下内容转换为 stdClass

stdClass Object ( 
    [responseData] => stdClass Object ( 
       [results] => Array ( 
            [0] => stdClass Object ( 
                [GsearchResultClass] => GwebSearch 
                [unescapedUrl] => http://www.1860-1960.com/shoes.html 
                [url] => http://www.1860-1960.com/shoes.html 
                [visibleUrl] => www.1860-1960.com 
                [cacheUrl] => http://www.google.com/search?q=cache:4bB2OicXg5EJ:www.1860-1960.com 
                [title] => Beautiful Antique Shoes and Boots, Vintage Fashions            [titleNoFormatting] => Beautiful Antique Shoes and Boots, Vintage Fashions 
                [content] => Victorian White Kid Child's Straight Sole Shoes c1850. Victorian Child's Needlepoint Bunny ... Lovely Vintage Shoes. Antique shoes or antique boots. ... 
            ) 
            [1] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.reproduction-vintage-shoes.com/ [url] => http://www.reproduction-vintage-shoes.com/ [visibleUrl] => www.reproduction-vintage-shoes.com [cacheUrl] => http://www.google.com/search?q=cache:ZIF1MW0oHlwJ:www.reproduction-vintage-shoes.com [title] => Reproduction Vintage Shoes, Affordable, Custom Made, Antique Footwear [titleNoFormatting] => Reproduction Vintage Shoes, Affordable, Custom Made, Antique Footwear [content] => Individually custom made reproduction Victorian and Edwardian shoes and boots. Historically accurate in appearance and made by a dance shoe maker; ...  ) 
            [2] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://fineartamerica.com/featured/mv--antique-shoes-nancy-ferrier.html [url] => http://fineartamerica.com/featured/mv--antique-shoes-nancy-ferrier.html [visibleUrl] => fineartamerica.com [cacheUrl] => http://www.google.com/search?q=cache:F3D-ay-THp4J:fineartamerica.com [title] => MV - Antique Shoes Photograph by Nancy Ferrier - MV - Antique ...  [titleNoFormatting] => MV - Antique Shoes Photograph by Nancy Ferrier - MV - Antique ... [content] => Aug 24, 2009 ... MV - Antique Shoes Photograph by Nancy Ferrier, MV - Antique Shoes Photograph, MV - Antique Shoes Photograph for Sale, MV - Antique Shoes ...  ) 
            [3] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.bobbydene.com/ [url] => http://www.bobbydene.com/ [visibleUrl] => www.bobbydene.com [cacheUrl] => http://www.google.com/search?q=cache:mHJnlzmDYf4J:www.bobbydene.com [title] => BobbyDene's Vintage Clothing, Victorian, Edwardian, Vintage ...  [titleNoFormatting] => BobbyDene's Vintage Clothing, Victorian, Edwardian, Vintage ... [content] => Victorian, Edwardian, 1920, 1940, vintage clothing, vintage dresses, antique clothes, hats, shoes, boots, jewelry, and collectables. ) ) 
       [cursor] => stdClass Object ( 
           [pages] => Array ( 
                [0] => stdClass Object ( [start] => 0 [label] => 1 ) 
                [1] => stdClass Object ( [start] => 4 [label] => 2 ) 
                [2] => stdClass Object ( [start] => 8 [label] => 3 ) 
                [3] => stdClass Object ( [start] => 12 [label] => 4 ) 
                [4] => stdClass Object ( [start] => 16 [label] => 5 ) 
                [5] => stdClass Object ( [start] => 20 [label] => 6 ) 
                [6] => stdClass Object ( [start] => 24 [label] => 7 ) 
                [7] => stdClass Object ( [start] => 28 [label] => 8 ) 
            ) 
        [estimatedResultCount] => 4370000 
        [currentPageIndex] => 0 
        [moreResultsUrl] => http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=antique+shoes 
        ) 
    ) 
    [responseDetails] => 
    [responseStatus] => 200 
) 

我需要的只是输出 [estimatedResultCount] 的数字(4370000),但无论我尝试多少种不同的方法,我都无法正确解析它。

I'm an intermediate PHP programmer, but am struggling with the output of the Google AJAX API. I have the following converted to stdClass

stdClass Object ( 
    [responseData] => stdClass Object ( 
       [results] => Array ( 
            [0] => stdClass Object ( 
                [GsearchResultClass] => GwebSearch 
                [unescapedUrl] => http://www.1860-1960.com/shoes.html 
                [url] => http://www.1860-1960.com/shoes.html 
                [visibleUrl] => www.1860-1960.com 
                [cacheUrl] => http://www.google.com/search?q=cache:4bB2OicXg5EJ:www.1860-1960.com 
                [title] => Beautiful Antique Shoes and Boots, Vintage Fashions            [titleNoFormatting] => Beautiful Antique Shoes and Boots, Vintage Fashions 
                [content] => Victorian White Kid Child's Straight Sole Shoes c1850. Victorian Child's Needlepoint Bunny ... Lovely Vintage Shoes. Antique shoes or antique boots. ... 
            ) 
            [1] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.reproduction-vintage-shoes.com/ [url] => http://www.reproduction-vintage-shoes.com/ [visibleUrl] => www.reproduction-vintage-shoes.com [cacheUrl] => http://www.google.com/search?q=cache:ZIF1MW0oHlwJ:www.reproduction-vintage-shoes.com [title] => Reproduction Vintage Shoes, Affordable, Custom Made, Antique Footwear [titleNoFormatting] => Reproduction Vintage Shoes, Affordable, Custom Made, Antique Footwear [content] => Individually custom made reproduction Victorian and Edwardian shoes and boots. Historically accurate in appearance and made by a dance shoe maker; ...  ) 
            [2] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://fineartamerica.com/featured/mv--antique-shoes-nancy-ferrier.html [url] => http://fineartamerica.com/featured/mv--antique-shoes-nancy-ferrier.html [visibleUrl] => fineartamerica.com [cacheUrl] => http://www.google.com/search?q=cache:F3D-ay-THp4J:fineartamerica.com [title] => MV - Antique Shoes Photograph by Nancy Ferrier - MV - Antique ...  [titleNoFormatting] => MV - Antique Shoes Photograph by Nancy Ferrier - MV - Antique ... [content] => Aug 24, 2009 ... MV - Antique Shoes Photograph by Nancy Ferrier, MV - Antique Shoes Photograph, MV - Antique Shoes Photograph for Sale, MV - Antique Shoes ...  ) 
            [3] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.bobbydene.com/ [url] => http://www.bobbydene.com/ [visibleUrl] => www.bobbydene.com [cacheUrl] => http://www.google.com/search?q=cache:mHJnlzmDYf4J:www.bobbydene.com [title] => BobbyDene's Vintage Clothing, Victorian, Edwardian, Vintage ...  [titleNoFormatting] => BobbyDene's Vintage Clothing, Victorian, Edwardian, Vintage ... [content] => Victorian, Edwardian, 1920, 1940, vintage clothing, vintage dresses, antique clothes, hats, shoes, boots, jewelry, and collectables. ) ) 
       [cursor] => stdClass Object ( 
           [pages] => Array ( 
                [0] => stdClass Object ( [start] => 0 [label] => 1 ) 
                [1] => stdClass Object ( [start] => 4 [label] => 2 ) 
                [2] => stdClass Object ( [start] => 8 [label] => 3 ) 
                [3] => stdClass Object ( [start] => 12 [label] => 4 ) 
                [4] => stdClass Object ( [start] => 16 [label] => 5 ) 
                [5] => stdClass Object ( [start] => 20 [label] => 6 ) 
                [6] => stdClass Object ( [start] => 24 [label] => 7 ) 
                [7] => stdClass Object ( [start] => 28 [label] => 8 ) 
            ) 
        [estimatedResultCount] => 4370000 
        [currentPageIndex] => 0 
        [moreResultsUrl] => http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=antique+shoes 
        ) 
    ) 
    [responseDetails] => 
    [responseStatus] => 200 
) 

All I need from it is to output the [estimatedResultCount]'s number (4370000), but no matter how many different ways I try it, I'm not able to parse it correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南薇 2024-08-13 23:52:34
$obj->responseData->cursor->estimatedResultCount
$obj->responseData->cursor->estimatedResultCount
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文