forked from OfficialIncubo/BeatDrop-Music-Visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_utils.cpp
More file actions
22 lines (20 loc) · 724 Bytes
/
json_utils.cpp
File metadata and controls
22 lines (20 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <nlohmann/json.hpp>
#include <string>
#include <iostream>
using json = nlohmann::json;
class JsonUtils {
public:
static std::string ParseResponse(const std::wstring& response) {
try {
// Convert wstring to string
std::string responseStr(response.begin(), response.end());
// Parse the JSON response
json jsonResponse = json::parse(responseStr);
// Extract the desired field (e.g., "text" from the response)
return jsonResponse["choices"][0]["text"].get<std::string>();
} catch (const std::exception& e) {
std::cerr << "JSON parsing error: " << e.what() << std::endl;
return "";
}
}
};