| 291 | } |
| 292 | |
| 293 | std::string json_array(const std::string& json, const std::string& key) { |
| 294 | std::string pattern = "\"" + key + "\":"; |
| 295 | size_t pos = json.find(pattern); |
| 296 | if (pos == std::string::npos) return "[]"; |
| 297 | size_t start = pos + pattern.size(); |
| 298 | while (start < json.size() && (json[start] == ' ' || json[start] == '\t')) ++start; |
| 299 | if (start >= json.size() || json[start] != '[') return "[]"; |
| 300 | int depth = 1; |
| 301 | size_t end = start + 1; |
| 302 | while (end < json.size() && depth > 0) { |
| 303 | if (json[end] == '[') depth++; |
| 304 | else if (json[end] == ']') depth--; |
| 305 | end++; |
| 306 | } |
| 307 | return json.substr(start, end - start); |
| 308 | } |
| 309 | |
| 310 | void Metrics::parse(const std::string& json) { |
| 311 | success = json_bool(json, "success", false); |