如何在json数组中获取谷歌自定义搜索结果

时间:2016-07-21 09:15:45

标签: android json google-custom-search

我想在谷歌最新的自定义搜索中将谷歌搜索结果作为json数组。

如何实现代码。

例如:

 {
    "responseData": {` `
        "results": [
            {
      ` `          "GsearchResultClass ": "GwebSearch",
                "unescapedUrl": "http:/ / en.wikipedia.org/wiki/Paris_Hilton",
                "url"   : "http    ://    en.wikipedi a.org/wiki/Paris_Hilton",
                "visibleUrl  "  : "en.wikipedia .org",
                "cacheUrl    "    : "http://www.google.com/search?q=cache:TwrPfhd22hYJ:en.wikipedia.org",
                "title": "<   b>Paris Hilton</b   > - Wikipedia, the free encyclopedia",
                "titleNoFormatting": "Paris Hilton - Wikipedia, the free encyclopedia",
                "content": "[1] In 2006, she released her debut album..."
            },
            {
                "GsearchResultClass": "GwebSearch",
                "unescapedUrl": "http://`   `www.imdb.com/name/nm0385296/",
                "url": "http://`    `www.imdb.com/name/nm0385296/",
                "visibleUrl":     "www.imdb.com",
                "cacheUrl":      "http://www.google.com/search?q=cache:1i34KkqnsooJ:www.imdb.com",
                "title": "<b>    Paris Hilton</b>",
                "titleNoFormatting": "Paris Hilton",
                "content": "    Self: Zoolander. Socialite <b>Paris Hilton</b>..."
            }
        ]

1 个答案:

答案 0 :(得分:3)

如果您想要自定义搜索结果。 请阅读Google的Custom Search Engine (free)

Create custom search engine

然后转到链接以创建自定义搜索:

https://cse.google.com/cse/

<强>

你应该去:

Google search API

点击链接:在API Explorer中试用此API

插入参数:

  • https://www.googleapis.com/customsearch/v1?”
    • “q =”+关键字(例如:“巴黎+希尔顿”)
    • “&amp; cx =”+您CSE
    • 的cx代码
    • “&amp; key =”+您的授权API密钥[在链接API project中,点击:A project is needed to enable APIs + Create project,然后转到'API&amp; auth'并在'自定义搜索API']中激活
    • “num =”+要返回的搜索结果数(整数)

Execute以格式JSON显示结果。