55inline std::map<std::string, std::vector<double>>
read_json(
const std::string &filename) {
56 std::ifstream file(filename);
57 if (!file.is_open()) {
61 std::stringstream buffer;
62 buffer << file.rdbuf();
63 std::string content = buffer.str();
65 std::map<std::string, std::vector<double>> data;
69 while (pos < content.length()) {
71 size_t quote_start = content.find(
'"', pos);
72 if (quote_start == std::string::npos)
75 size_t quote_end = content.find(
'"', quote_start + 1);
76 if (quote_end == std::string::npos)
79 std::string key = content.substr(quote_start + 1, quote_end - quote_start - 1);
83 size_t colon = content.find(
':', pos);
84 if (colon == std::string::npos)
89 size_t bracket_start = content.find(
'[', pos);
90 if (bracket_start == std::string::npos)
92 pos = bracket_start + 1;
94 size_t bracket_end = content.find(
']', pos);
95 if (bracket_end == std::string::npos)
99 std::string array_content = content.substr(pos, bracket_end - pos);
100 std::vector<double> vec;
101 std::stringstream ss(array_content);
102 std::string number_str;
104 while (std::getline(ss, number_str,
',')) {
106 number_str.erase(0, number_str.find_first_not_of(
" \t\n\r"));
107 number_str.erase(number_str.find_last_not_of(
" \t\n\r") + 1);
108 if (!number_str.empty()) {
110 vec.push_back(std::stod(number_str));
111 }
catch (
const std::exception &e) {
113 number_str +
"': " + e.what());
119 pos = bracket_end + 1;