VC++获取网页回来的JSON数据
VC++获取网页返回的JSON数据
1、直接在浏览器打开“http://sg1.api.bing.com/qsonhs.aspx?q=设计”会返回JSON数据
2、在VC++中
获取到的szAllData数据却是:{"AS":{"Query":"设计","FullResults":0}}
这是哪里出问题了呢?
------解决方案--------------------
1、直接在浏览器打开“http://sg1.api.bing.com/qsonhs.aspx?q=设计”会返回JSON数据
2、在VC++中
bool CQuickSearchDlg::getSearchJson(const TCHAR * keyword, TCHAR * json)
{
wchar_t isonUrl[200] = _T("http://sg1.api.bing.com/qsonhs.aspx?q=设计");
CInternetSession cSession;
CHttpFile *cFile;
char sRecived[1024] = {0};
CString szAllData = _T("");
try
{
cFile = (CHttpFile *)cSession.OpenURL(isonUrl);
}
catch(CInternetException * m_pException)
{
cFile = NULL;
m_pException->m_dwError;
m_pException->Delete();
cSession.Close();
AfxMessageBox(_T("CInternetException"));
return false;
}
DWORD dwStatusCode;
cFile->QueryInfoStatusCode(dwStatusCode);
if(dwStatusCode == HTTP_STATUS_OK)
{
while(cFile->ReadString((LPTSTR)sRecived, 1024) != NULL)
szAllData += sRecived;
int a = 0;
}
else
{
MessageBox(_T("请求失败。。。。"));
}
cFile->Close();
delete cFile;
cSession.Close();
return true;
}
获取到的szAllData数据却是:{"AS":{"Query":"设计","FullResults":0}}
这是哪里出问题了呢?
vc++
json
CInternetSession
OpenURL
------解决方案--------------------
char utf[10];
char utff[30];
for (int n = 0; n < strlen(utf); n ++)
{
sprintf(&utff[n * 3], "%%%02x", utf[n]);
}