blob: 7e7de8dd9ebeaf982512af1621f55b5f2968b222 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
//
// Created by thecharlesblake on 11/13/17.
//
#include <fstream>
#include <sstream>
#include "util.h"
using namespace std;
using namespace rapidjson;
Document util::get_file_json(const string& filename) {
// Reads the file into a string
std::ifstream ifstr(filename);
std::stringstream buf;
buf << ifstr.rdbuf();
if (ifstr.fail()) {
throw runtime_error("could not read file " + filename);
} else {
Document d;
d.Parse(buf.str().c_str());
if (d.HasParseError()) {
throw runtime_error(filename + " not valid json");
} else {
return d;
}
}
}
void util::json_parse_err(const string& msg) {
throw runtime_error("Error in JSON doc: " + msg);
}
|