You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using json = nlohmann::json; using namespace std; int main() { ifstream file ("data.json", ios::in | ios::ate); if (!file.is_open()) return 1; streampos size = file.tellg(); file.seekg(0, ios::beg); char *memblock = new char[size]; file.read(memblock, size); file.close();
json data = json::parse(memblock); // another approach string s = memblock; json data = json::parse(s); // or json data = json::parse(s.c_str()); ...
All three methods to initialize json give runtime error : terminate called after throwing an instance of 'std::invalid_argument' what(): parse error - unexpected number literal; expected string literal [1] 8754 abort (core dumped) ./a.out
The json file is { 1 : { "name": "himanshu" }, 2 : { "name":"shekhar" } }
Activity
himanshub16 commentedon Oct 15, 2016
Got it. My JSON files are syntactically wrong.
It should be :
{ "1" : { .. } , "2" : { ... } }They should be strings. 😞
Sorry to bother you guys.