我正在使用Laravel来查询Google的搜索API。以下是执行此操作的代码:
Route::get('google/(:any)', function($query)
{
$uri = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".$query;
$response = Httpful::get($uri)->send();
$r = json_decode($response);
return Response::json($r);
});
这可以通过http://example.com/w/google/queryhere访问。
我也试图在JavaScript中进行多个请求并解析JSON。
$.when( $.ajax(google), $.ajax(bing), $.ajax(yahoo)).then(function(resp1, resp2, resp3)
{
var obj = jQuery.parseJSON(resp1);
});
然而,在使用parseJSON方法时,我得到了一个意外的语法标记。我不知道哪里出错了。