-
Notifications
You must be signed in to change notification settings - Fork 2.7k
what is "what()" function and why is jsoncpp throwing an exception about invalid syntax of it? #1325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You've taken this pretty far! I admire your persistence. Okay what's going on now is not a jsoncpp bug. It's more of a general programming help request at this point. This What's happening here is that all those I recommend breaking these deep accessors into simpler expressions (maybe with a helper function), Good luck. PS: To your original question, |
ah, ok... I'll try to do that. Here's the simple JSON file and my code rn. I did look up the docs and followed some of the code example. {
"n":1,
"data":
{
"name":"Chrome",
"description":"Browse the internet.",
"isEnabled":true
}
} Code #include <json/json.h>
#include <fstream>
#include <iostream>
int main() {
Json::Value root;
std::ifstream json_file("./sample.json", std::ifstream::binary);
json_file >> root;
// std::cout << root;
std::cout << "\n\n";
std::cout << "Desktop " << root["n"] << "\n";
std::cout << "=========================\n";
std::cout << "Application Details: \n";
std::cout << "Name: " << root["data"].get("name", "n/a").asString() << "\n";
std::cout << "Description: " << root["data"].get("description", "n/a").asString() << "\n";
std::cout << "Enabled: " << root["data"].get("isEnabled", "true").asString() << "\n";
return 0;
} Will close this issue as it is solved. :) |
So I was trying to test out this json parsing library with a sample JSON file I made. After some hiccups and some help from here and the codeblocks forum (I use Code::Blocks), I was able to build the program. However, when it ran, it returned an error/status code 3.
CONSOLE OUTPUT:
The sample JSON file has been checked and is in a valid JSON format.
The code used the
Json::Value
type only.Full Code:
Please help, or maybe fix it... Thank you.
The text was updated successfully, but these errors were encountered: