1

これは私がグーグルカスタム検索APIから得ている応答です

ウェブサイトのタイトル、URL、その他の情報をデータベースに直接挿入したい。

json_decodeを使用していますが、応答を取得できないようです

助けてください

    {
"kind": "customsearch#search",
"url": {
    "type": "application/json",
    "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
},
"queries": {
    "nextPage": [
        {
            "title": "Google Custom Search - online shopping mall",
            "totalResults": "35200000",
            "searchTerms": "online shopping mall",
            "count": 10,
            "startIndex": 11,
            "inputEncoding": "utf8",
            "outputEncoding": "utf8",
            "safe": "off",
            "cx": "013036536707430787589:_pqjad5hr1a"
        }
    ],
    "request": [
        {
            "title": "Google Custom Search - online shopping mall",
            "totalResults": "35200000",
            "searchTerms": "online shopping mall",
            "count": 10,
            "startIndex": 1,
            "inputEncoding": "utf8",
            "outputEncoding": "utf8",
            "safe": "off",
            "cx": "013036536707430787589:_pqjad5hr1a"
        }
    ]
},
"context": {
    "title": "Custom Search"
},
"searchInformation": {
    "searchTime": 0.324098,
    "formattedSearchTime": "0.32",
    "totalResults": "35200000",
    "formattedTotalResults": "35,200,000"
},
"items": [
    {
        "kind": "customsearch#result",
        "title": "Online Shopping Mall-Shopping & Business Social Network",
        "htmlTitle": "<b>Online Shopping Mall</b>-Shopping &amp; Business Social Network",
        "link": "http://onlineshoppingmall.ning.com/",
        "displayLink": "onlineshoppingmall.ning.com",
        "snippet": "A One-Stop shopping & business social network created by a family of merchants   offering value, unique treasures, and convenience!",
        "htmlSnippet": "A One-Stop <b>shopping</b> &amp; business social network created by a family of merchants <br>  offering value, unique treasures, and convenience!",
        "cacheId": "5uXNYD4cCQ0J",
        "formattedUrl": "onlineshoppingmall.ning.com/",
        "htmlFormattedUrl": "<b>onlineshoppingmall</b>.ning.com/",
        "pagemap": {
            "cse_image": [
                {
                    "src": "http://i43.tinypic.com/15wm45e.jpg"
                }
            ],
            "cse_thumbnail": [
                {
                    "width": "100",
                    "height": "100",
                    "src": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQy2PZIPYcAjBAPOYgKgqnWfb9kJLCW4Xx7_QZcdRmfP_MeGPH9HZNnlA"
                }
            ],
            "metatags": [
                {
                    "title": "Online Shopping Mall-Shopping & Business Social Network"
                }
            ]
        }
    },
    {
        "kind": "customsearch#result",
        "title": "Online shopping malls - Wikipedia, the free encyclopedia",
        "htmlTitle": "<b>Online shopping malls</b> - Wikipedia, the free encyclopedia",
        "link": "http://en.wikipedia.org/wiki/Online_shopping_malls",
        "displayLink": "en.wikipedia.org",
        "snippet": "Online shopping malls are websites that have a directory of online shopping   stores. Stores may include Best Buy, Aeropostale, Home Depot, Sears, Expedia, ...",
        "htmlSnippet": "<b>Online shopping malls</b> are websites that have a directory of online shopping <br>  stores. Stores may include Best Buy, Aeropostale, Home Depot, Sears, Expedia, <b>...</b>",
        "cacheId": "dA73fRSS6KMJ",
        "formattedUrl": "en.wikipedia.org/wiki/Online_shopping_malls",
        "htmlFormattedUrl": "en.wikipedia.org/wiki/<b>Online</b>_<b>shopping</b>_<b>malls</b>"
    },
    {
        "kind": "customsearch#result",
        "title": "Shop for Home, Outdoor, Electronics and Apparel Products at ...",
        "htmlTitle": "<b>Shop</b> for Home, Outdoor, Electronics and Apparel Products at <b>...</b>",
        "link": "http://www.skymall.com/",
        "displayLink": "www.skymall.com",
        "snippet": "SkyMall shopping magazine is your home for the best online catalog shopping!   Browse from home living, décor, audio, ipod, electronics and apparel. Purchase ...",
        "htmlSnippet": "SkyMall <b>shopping</b> magazine is your home for the best <b>online</b> catalog <b>shopping</b>! <br>  Browse from home living, décor, audio, ipod, electronics and apparel. Purchase <b>...</b>",
        "cacheId": "GWXI7WmQ2UUJ",
        "formattedUrl": "www.skymall.com/",
        "htmlFormattedUrl": "www.sky<b>mall</b>.com/",
        "pagemap": {
            "cse_image": [
                {
                    "src": "http://www.skymall.com/images/feature_a1a.jpg"
                }
            ],
            "cse_thumbnail": [
                {
                    "width": "239",
                    "height": "210",
                    "src": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTljZ4YcdN7ZRJlVMeTlYF8sbuwLm0VRhg0oZnLDX1elV3j-dmO22t68do"
                }
            ],
            "metatags": [
                {
                    "copyright": "Copyright © 2012 SkyMall, Inc. All right reserved.",
                    "designer": "www.objectinnovation.com",
                    "classification": "online shopping, shopping, gifts, catalog sales"
                }
            ]
        }
    },
    {
        "kind": "customsearch#result",
        "title": "Sassy Shops, Your Premiere Online Mall for All Things Fabulous!",
        "htmlTitle": "Sassy <b>Shops</b>, Your Premiere <b>Online Mall</b> for All Things Fabulous!",
        "link": "http://www.sassyshops.com/",
        "displayLink": "www.sassyshops.com",
        "snippet": "Sassy Shops, Your Premiere Online Mall for All Things Fabulous! Throw on some   comfy pj's, grab a cup of hot cocoa or java and enjoy shopping from the ...",
        "htmlSnippet": "Sassy <b>Shops</b>, Your Premiere <b>Online Mall</b> for All Things Fabulous! Throw on some <br>  comfy pj&#39;s, grab a cup of hot cocoa or java and enjoy <b>shopping</b> from the <b>...</b>",
        "cacheId": "jaAQALpU96oJ",
        "formattedUrl": "www.sassyshops.com/",
        "htmlFormattedUrl": "www.sassy<b>shops</b>.com/",
        "pagemap": {
            "cse_image": [
                {
                    "src": "http://sassyshops.com/images/pinkbug/headerlogo.gif"
                }
            ],
            "cse_thumbnail": [
                {
                    "width": "268",
                    "height": "188",
                    "src": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQ4-X6hJVkuF_fFclW9e8IXDKtqXJ-JTF64QwI4xfTawHkMsnsOAuGCXsQv"
                }
            ]
        }
    },
    {
        "kind": "customsearch#result",
        "title": "Home Page - Shop Online at MileagePlus Shopping",
        "htmlTitle": "Home Page - <b>Shop Online</b> at MileagePlus <b>Shopping</b>",
        "link": "https://www.mileageplusshopping.com/",
        "displayLink": "www.mileageplusshopping.com",
        "snippet": "Home Page - Shop Online at MileagePlus Shopping.",
        "htmlSnippet": "Home Page - <b>Shop Online</b> at MileagePlus <b>Shopping</b>.",
        "formattedUrl": "https://www.mileageplusshopping.com/",
        "htmlFormattedUrl": "https://www.mileageplus<b>shopping</b>.com/",
        "pagemap": {
            "cse_image": [
                {
                    "src": "https://a248.e.akamai.net/f/248/35975/5d/i.mallnetworks.com/images/global/40cf5e879cc6088d7d2086a512fd79b19b0aaa2a.jpg"
                }
            ],
            "cse_thumbnail": [
                {
                    "width": "96",
                    "height": "72",
                    "src": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSDE8da0POrgf12M_3zBGdueaQfT0AHYBbz7Dkxnm7QQbHUegSwMEPleg"
                }
            ]
        }
    },
    {
        "kind": "customsearch#result",
        "title": "We-Care.com Online Shopping Mall :: Shop With Purpose :: Macy's ...",
        "htmlTitle": "We-Care.com <b>Online Shopping Mall</b> :: Shop With Purpose :: Macy&#39;s <b>...</b>",
        "link": "http://www.we-care.com/",
        "displayLink": "www.we-care.com",
        "snippet": "The online shopping mall that provides coupons for your favorite merchants and   donates a percentage of what you spend to your favorite nonprofit, school, ...",
        "htmlSnippet": "The <b>online shopping mall</b> that provides coupons for your favorite merchants and <br>  donates a percentage of what you spend to your favorite nonprofit, school, <b>...</b>",
        "cacheId": "RgiiDvqLcscJ",
        "formattedUrl": "www.we-care.com/",
        "htmlFormattedUrl": "www.we-care.com/",
        "pagemap": {
            "cse_image": [
                {
                    "src": "http://cdn.we-care.com/Content/images/addCause.gif"
                }
            ],
            "cse_thumbnail": [
                {
                    "width": "249",
                    "height": "100",
                    "src": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQoOFWkNEJQDtz21dtLqwegJiXYruxvZ8UFLaFWH27knH2sIYqfvmPZOg"
                }
            ]
        }
    },
    {
        "kind": "customsearch#result",
        "title": "Online Shopping vs. Driving to the Mall: The Greener Way to Buy ...",
        "htmlTitle": "<b>Online Shopping</b> vs. Driving to the <b>Mall</b>: The Greener Way to Buy <b>...</b>",
        "link": "http://www.treehugger.com/culture/online-shopping-vs-driving-to-the-mall-the-greener-way-to-buy.html",
        "displayLink": "www.treehugger.com",
        "snippet": "Feb 13, 2009 ... When it comes to the way we procure the goods we use in our lives, there are   some mixed messages out there. Buying local is advertised as a ...",
        "htmlSnippet": "Feb 13, 2009 <b>...</b> When it comes to the way we procure the goods we use in our lives, there are <br>  some mixed messages out there. Buying local is advertised as a <b>...</b>",
        "cacheId": "9gBcwLGsuq8J",
        "formattedUrl": "www.treehugger.com/.../online-shopping-vs-driving-to-the-mall-the-greener- way-to-buy.html",
        "htmlFormattedUrl": "www.treehugger.com/.../<b>online</b>-<b>shopping</b>-vs-driving-to-the-<b>mall</b>-the-greener- way-to-buy.html",
        "pagemap": {
            "cse_image": [
                {
                    "src": "http://media.treehugger.com/assets/images/2011/10/shopping-mall-online-shopping-which-greener.jpg.400x300_q90_crop-smart.jpg"
                }
            ],
            "cse_thumbnail": [
                {
                    "width": "259",
                    "height": "194",
                    "src": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRQ2PXb8tGbfICgwAmSS9m1XtEq117PujeITme8mBELX6zW3JfzgGVHEYw"
                }
            ],
            "metatags": [
                {
                    "og:title": "Online Shopping vs. Driving to the Mall: The Greener Way to Buy",
                    "og:type": "article",
                    "og:url": "http://www.treehugger.com/culture/online-shopping-vs-driving-to-the-mall-the-greener-way-to-buy.html",
                    "og:image": "http://media.treehugger.com/assets/images/2011/10/shopping-mall-online-shopping-which-greener.jpg.400x300_q90_crop-smart.jpg",
                    "og:site_name": "TreeHugger",
                    "og:description": "When it comes to the way we procure the goods we use in our lives, there are some mixed messages out there. Buying local is advertised as a green way to go -- and it can be -- but so is acquiring",
                    "fb:app_id": "133255656700169"
                }
            ]
        }
    },
    {
        "kind": "customsearch#result",
        "title": "Shabby Lane Shops - Great online Shopping Mall & Unique Web ...",
        "htmlTitle": "Shabby Lane Shops - Great <b>online Shopping Mall</b> &amp; Unique Web <b>...</b>",
        "link": "http://shabbylaneshops.com/",
        "displayLink": "shabbylaneshops.com",
        "snippet": "Shabby Lane Shops Great online shopping mall and Web design. Let us   advertise for you. Come shop with us, come join us.",
        "htmlSnippet": "Shabby Lane Shops Great <b>online shopping mall</b> and Web design. Let us <br>  advertise for you. Come shop with us, come join us.",
        "cacheId": "FhVJ8g2L5i8J",
        "formattedUrl": "shabbylaneshops.com/",
        "htmlFormattedUrl": "shabbylane<b>shops</b>.com/"
    },
    {
        "kind": "customsearch#result",
        "title": "Online Shopping Malls, Discount Stores, Outlet Malls, Shopping ...",
        "htmlTitle": "<b>Online Shopping Malls</b>, Discount Stores, Outlet Malls, Shopping <b>...</b>",
        "link": "http://www.milehimall.com/",
        "displayLink": "www.milehimall.com",
        "snippet": "Shop at online shopping malls, discount stores and gift shops at Mile Hi Mall.   Browse home and garden, beauty, electronics, sporting goods, jewelry and ...",
        "htmlSnippet": "Shop at <b>online shopping malls</b>, discount stores and gift shops at Mile Hi Mall. <br>  Browse home and garden, beauty, electronics, sporting goods, jewelry and <b>...</b>",
        "cacheId": "PaF59OCuEJ4J",
        "formattedUrl": "www.milehimall.com/",
        "htmlFormattedUrl": "www.milehi<b>mall</b>.com/",
        "pagemap": {
            "cse_image": [
                {
                    "src": "http://www.shareasale.com/image/27020/child-costumes125x125.jpg"
                }
            ],
            "cse_thumbnail": [
                {
                    "width": "100",
                    "height": "100",
                    "src": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSmvuJxRjL6C_aprr--I7detJud6l_jKXdgwrQP43bZkm449F-vp2T-"
                }
            ]
        }
    },
    {
        "kind": "customsearch#result",
        "title": "Online Shopping Mall - Online Stores | Shopping Centers | Outlet Malls",
        "htmlTitle": "<b>Online Shopping Mall</b> - Online Stores | Shopping Centers | Outlet Malls",
        "link": "http://www.online-internet-shopping-mall.com/",
        "displayLink": "www.online-internet-shopping-mall.com",
        "snippet": "Many Online Stores on this shopping mall website, online shopping malls,   shopping centers, outlet malls are just a click away at online shopping mall.",
        "htmlSnippet": "Many Online Stores on this shopping mall website, <b>online shopping malls</b>, <br>  shopping centers, outlet malls are just a click away at <b>online shopping mall</b>.",
        "cacheId": "5CzLC80fRAkJ",
        "formattedUrl": "www.online-internet-shopping-mall.com/",
        "htmlFormattedUrl": "www.<b>online</b>-internet-<b>shopping</b>-<b>mall</b>.com/",
        "pagemap": {
            "cse_image": [
                {
                    "src": "http://www.online-internet-shopping-mall.com/images/online-internet-shopping-mall1.png"
                }
            ],
            "cse_thumbnail": [
                {
                    "width": "225",
                    "height": "225",
                    "src": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQGTMNDeUWOwQ5ODDgGfav35KPGyn0ijbSXrhgSdgkNb097NT4HCJOz-2Yo"
                }
            ]
        }
    }
]

}

4

1 に答える 1

0

結果が得られている場合 (あなたのように見えます)、json_decode は正常に動作するはずです。

$json_array = json_decode($json,true);

foreach($json_array['items'] as $result)
{
    echo "title = ".$result['title']."<br>";
    echo "link = ".$result['link']."<br>";
    echo "<hr>";

}
于 2012-11-07T18:02:59.890 に答える