微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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(); } }

原文地址:https://www.jb51.cc/json/289526.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐