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" } }
The text was updated successfully, but these errors were encountered:
I tried handling files, but it lead to runtime errors. Could you please help me figure out the bug?
#include <iostream>
#include <fstream>
#include "json.hpp"
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" } }
The text was updated successfully, but these errors were encountered: