Basically doing this simple request i get an error that says: enter image description here : Run-time check failure #2 - Stack around the variable 'root' was corrupted. What could it be? My code basically just as the binance server for the time and then print it, I'm new to c++ so these are just some tests :
#include <iostream>
#include <curl/curl.h>
#include "json/json.h"
#include "json/reader.h"
#include "json/writer.h"
#include "json/value.h"
size_t WriteCallback(char* contents, size_t size, size_t nmemb, void* userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main()
{
CURL* curl;
CURLcode res;
std::string readBuffer;
Json::Value root;
Json::Reader reader;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.binance.com/api/v3/time");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
CURLcode res = curl_easy_perform(curl);
bool parsingSuccessful = reader.parse(readBuffer.c_str(), root); //parse process
if (!parsingSuccessful)
{
std::cout << "Failed to parse"
<< reader.getFormattedErrorMessages();
return 0;
}
std::cout << root.get("serverTime","").asString() << std::endl;
curl_easy_cleanup(curl);
}
return 0;
}