jsoncpp解析 json对象


void GetHttpValue::urlopen(std::string url) { std::string stTemp; char chTemp[1000]; ZeroMemory(chTemp,1000); HINTERNET hSession = Internetopen(_T("UrlTest"),INTERNET_OPEN_TYPE_PRECONfig,NULL,0); if (hSession != NULL) { HINTERNET hHttp = InternetopenUrl(hSession,url.c_str(),INTERNET_FLAG_DONT_CACHE,0); if (hHttp != NULL) { printf("%s\n\n",url.c_str()); BYTE Temp[MAXSIZE]; ULONG Number = 1; while (Number > 0) { InternetReadFile(hHttp,Temp,MAXSIZE - 1,&Number); Temp[Number] = '\0'; copyMemory(chTemp,Number); printf("%s",Temp); } InternetCloseHandle(hHttp); hHttp = NULL; } InternetCloseHandle(hSession); hSession = NULL; } stTemp = chTemp; cout << "=========================" << endl << endl;// 到这的作用:访问一个URL地址获取它的返回值(一个json对象) cout << stTemp << endl; std::string stResult = stTemp;//从这开始解析这个json对象 Json::Reader readerjson; Json::Value valueJson; if (readerjson.parse(stResult,valueJson)) { int code = valueJson["code"].asInt(); std::string msg = valueJson["msg"].asstring(); int userId = valueJson["data"]["userId"].asInt(); std::string nickName = valueJson["data"]["nickName"].asstring(); std::string headimgurL = valueJson["data"]["headimgurL"].asstring();//这里有多重包含 int gold = valueJson["data"]["gold"].asInt(); int sex = valueJson["data"]["sex"].asInt(); } }

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...