Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cpprestsdk json test
#include <cpprest\json.h>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
web::json::value root;
std::wstring filepath = L"config.json";
std::ifstream ifs;
ifs.open(filepath.c_str(), std::ifstream::in);
if (ifs)
{
try {
auto jsonResult = web::json::value::parse(ifs);
auto value = jsonResult.at(L"key").as_string();
auto value2 = jsonResult.at(L"anotherkey").as_string();
auto value3 = jsonResult.at(L"last").as_string();
}
catch (const std::exception& e) {
std::string reason = e.what();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment