第一步:建立控制台工程,配置libcurl
在stdafx.h中导入引用的libcurl库,在用的是静态链接
....... #define CURL_STATICLIB #include "curl\curl.h" #ifdef _DEBUG #pragma comment(lib,"libcurld.lib") #else #pragma comment(lib,"libcurl.lib") #endif #pragma comment ( lib, "ws2_32.lib" ) #pragma comment ( lib, "winmm.lib" ) #pragma comment ( lib, "wldap32.lib" ) #pragma comment(lib, "Advapi32.lib") ........
库文件的位置
第二步:配置JsonCpp库,如果想在工程中直接引用源码,请参考我之前的博客
第三步:上传json串
#include "stdafx.h"
#include
#include
//json
#include "json\json.h"
using namespace std;
//http://blog.csdn.net/wyansai/article/details/50764315
wstring AsciiToUnicode(const string& str)
{
// 预算-缓冲区中宽字节的长度
int unicodeLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0);
// 给指向缓冲区的指针变量分配内存
wchar_t *pUnicode = (wchar_t*)malloc(sizeof(wchar_t)*unicodeLen);
// 开始向缓冲区转换字节
MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, pUnicode, unicodeLen);
wstring ret_str = pUnicode;
free(pUnicode);
return ret_str;
}
string UnicodeToUtf8(const wstring& wstr)
{
// 预算-缓冲区中多字节的长度
int ansiiLen = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, nullptr, 0, nullptr, nullptr);
// 给指向缓冲区的指针变量分配内存
char *pAssii = (char*)malloc(sizeof(char)*ansiiLen);
// 开始向缓冲区转换字节
WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, pAssii, ansiiLen, nullptr, nullptr);
string ret_str = pAssii;
free(pAssii);
return ret_str;
}
string AsciiToUtf8(const string& str)
{
return UnicodeToUtf8(AsciiToUnicode(str));
}
//回调函数
size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
string data((const char*) ptr, (size_t) size * nmemb);
*((stringstream*) stream) UTF-8
以wstring类型保存的json,编码转换流程:Unicode--->UTF-8
