我正在尝试从网站读取JSON数据。我在Windows 10上使用具有MinGW编译器的Dev C ++。这是我尝试在静态项目中运行的教程中的JSON解析器:
#define CURL_STATICLIB
#include <cstdint>
#include <iostream>
#include <memory>
#include <string>
#include <sstream>
#include "curl.h"
#include "json.h"
namespace
{
std::size_t callback(
const char* in,
std::size_t size,
std::size_t num,
std::string* out)
{
const std::size_t totalBytes(size * num);
out->append(in, totalBytes);
return totalBytes;
}
}
int main()
{
const std::string url("http://date.jsontest.com/");
CURL* curl = curl_easy_init();
// Set remote URL.
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// Don't bother trying IPv6, which would increase DNS resolution time.
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
// Don't wait forever, …Run Code Online (Sandbox Code Playgroud)