1

カスタム検索エンジン用のGoogleAPIを使い始めたばかりで、次のような最初のリクエストを実行することに成功しました。

My_first_Search.php

 require_once 'apis/apiClient.php';
 require_once 'apis/contrib/apiCustomsearchService.php';
 session_start();

 $client = new apiClient();
 $client->setApplicationName('Google CustomSearch PHP Starter Application');
 // Docs: http://code.google.com/apis/customsearch/v1/using_rest.html
 // My developer key (simple api key).
 $client->setDeveloperKey('***********************************');
 $search = new apiCustomsearchService($client);


  // executing a search with your custom search id.
  $result = $search->cse->listCse('burrito', array(
  'cx' => '123456789123546789:*******', // The custom search engine ID to scope this search query.
  ));
 print "<pre>" . print_r($result, true) . "</pre>";

 // executing a search with the URL of a linked custom search engine.
 $result = $search->cse->listCse('burrito', array(
 'cref' => 'http://www.google.com/cse/samples/vegetarian.xml',
  ));
 print "<pre>" . print_r($result, true) . "</pre>";

出力: このファイルburritoは、キーワードの結果をJSON形式で正しく出力します

どうすれば脱塩してから、for-eachループを使用して結果を操作して以下を取得できますか?

  - Result title
  - Result description
  - URL

操作するJSON出力を確認するには、ここをクリックしてください

どんな助けでも大歓迎です。

4

1 に答える 1

1

「このファイル」はjsonを出力していません。JSONは、JSでの変数割り当てのテキスト表現です。例:の右側var x = ...json here...。そのダンプは、json文字列をデコードすることによって生成されたPHPデータ構造です。

言い換えれば、JSONを取得しているという事実にとらわれないでください-一度デコードされると、それは単なる別のPHP配列であり、通常のPHP配列操作とインデックスを使用してデータを取得します。

例えば

$arr['queries']['nextPage'][0]['title'] // Google Custom Search - burrito
于 2012-08-13T01:16:09.943 に答える