c++调用python,接收返回值为json类型,写出c++具体代码
时间: 2023-02-20 10:27:58 浏览: 108
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
#include <json/json.h>
int main(void)
{
CURL *curl;
CURLcode res;
json_object *json;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://chatgpt.openai.com/api/");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
else {
json = json_tokener_parse(data);
printf("Current date: %s\n", json_object_get_string(json));
}
curl_easy_cleanup(curl);
}
return 0;
}
阅读全文