mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-08 09:36:07 -05:00
Add action to enable extraction of values from json string
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <unordered_map>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -701,6 +702,24 @@ void LoadSplitterPos(QList<int> &sizes, obs_data_t *obj, const std::string name)
|
||||
obs_data_array_release(array);
|
||||
}
|
||||
|
||||
std::optional<std::string> GetJsonField(const std::string &jsonStr,
|
||||
const std::string &fieldToExtract)
|
||||
{
|
||||
try {
|
||||
nlohmann::json json = nlohmann::json::parse(jsonStr);
|
||||
auto it = json.find(fieldToExtract);
|
||||
if (it == json.end()) {
|
||||
return {};
|
||||
}
|
||||
if (it->is_string()) {
|
||||
return it->get<std::string>();
|
||||
}
|
||||
return it->dump();
|
||||
} catch (const nlohmann::json::exception &) {
|
||||
return {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
QStringList GetSourceNames()
|
||||
{
|
||||
auto sourceEnum = [](void *param, obs_source_t *source) -> bool /* -- */
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <obs-frontend-api.h>
|
||||
#include <deque>
|
||||
#include <unordered_map>
|
||||
#include <optional>
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -134,6 +135,8 @@ void SaveSplitterPos(const QList<int> &sizes, obs_data_t *obj,
|
||||
const std::string name);
|
||||
void LoadSplitterPos(QList<int> &sizes, obs_data_t *obj,
|
||||
const std::string name);
|
||||
std::optional<std::string> GetJsonField(const std::string &json,
|
||||
const std::string &id);
|
||||
|
||||
/* Legacy helpers */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user