我正在寻找从CrunchBase API中提取公司列表的数据,然后将该数据添加到数据库中的选择表中。我真的不知道从哪里开始。我一直在看cURL。
我现在所在的位置:
$url = "http://api.crunchbase.com/v/1/company/audible-coffee.js?api_key=API_KEY&callback=?";
$data = get_data($url);
// Note: ideally you should use DOM manipulation to inject the <base>
// tag inside the <head> section
$data = str_replace("<head>", "<head><base href=\"$url\">", $data);
echo $data;
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_close($ch);
return $data;
}
我想现在应该解析它,然后将数据存储在数据库中。
我为查找解析数据的代码所做的努力如下:
$json_string = '<url.json>';
$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata, true);
print_r($obj['Result']);
不幸的是,我不知道自己在做什么,因此非常感谢您提供任何有关更改内容或从此处出发的信息。
简单得多-直接访问URL,而不必担心cURL:
$url = "http://api.crunchbase.com/v/1/company/audible-coffee.js?api_key=API_KEY&callback=?";
$jsondata = file_get_contents($url);
$obj = json_decode($jsondata);
我在这里假设您问题中的URL是保证返回JSON字符串的API。str_replace
在您的第一个代码示例中,我不了解的目的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句