I am using a JSON example from the web as shown below.
{ "menu": "File", "commands": [ { "title": "New", "action":"CreateDoc" }, { "title": "Open", "action": "OpenDoc" }, { "title": "Close", "action": "CloseDoc" } ] }
I tried loading this in two different parsers: one in C ++ and Python.
Here's a Python trace.
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/json/__init__.py", line 267, in load parse_constant=parse_constant, **kw) File "/usr/lib/python2.6/json/__init__.py", line 307, in loads return _default_decoder.decode(s) File "/usr/lib/python2.6/json/decoder.py", line 319, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.6/json/decoder.py", line 338, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded
And here is what jsoncpp reports.
* Line 1, Column 1 Syntax error: value, object or array expected.
Any clues what am I doing wrong?
Edit:
Ok, here is some code. For some reason, Python is working. I did nothing but go to the store. It should be a Python function - go to the store, random errors will disappear. These Python developers are geniuses.
But to the point. Here is the C ++ code.
bool CFG::CFG_Init( const char* path ) { bool r = reader.parse( path, root ); if( r ) { return true; } else { std::cout << reader.getFormatedErrorMessages() << std::endl; return false; } }
I tried this when the "path" was std :: string, and also the same. I call the method as follows:
if( !CFG_Init("test.json") ) { error("Couldn't load configuration."); }
And here is the class.
class CFG: virtual Evaluator { Json::Reader reader; public: Json::Value root; bool CFG_Init( const char* path); Json::Value CFG_Fetch_Raw(Json::Value section, std::string key, Json::Value defval); Json::Value CFG_Fetch(Json::Value section, std::string key, Json::Value defval ); };