#include #include #include #include "include/rapidjson/document.h" #include "include/rapidjson/writer.h" #include "include/rapidjson/stringbuffer.h" using namespace rapidjson; static std::string buffer; static int writer(char* data, size_t size, size_t nmemb, std::string* buffer) { int result = 0; if (buffer != NULL) { buffer->append(data, size* nmemb); result = size* nmemb; } return result; } static std::string vk(std::string method, std::string data, std::string token = "e5eadb782bd8huivamanetokende3e33a31ee7e2fe6e93378a72124e7ec3690a81352f82233a81f0") { CURL* curl; CURLcode result; std::string url = "https://api.vk.com/method/"+method; curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); curl_easy_setopt(curl, CURLOPT_POST, 1); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str()); result = curl_easy_perform(curl); } return buffer; } int main(int argc, char* argv[]) { std::string ss = vk("users.get", "user_ids=cubexx&fields=city"); const char* json = ss.c_str(); Document d; d.Parse(json); Value& s = d["response"]; Value& sa = s["uid"]; StringBuffer buffer; Writer writer(buffer); d.Accept(writer); std::cout << buffer.GetString(); return 0; }