diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-12-14 19:26:07 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-02-02 15:46:34 +0100 |
| commit | f4190b283fc65fa21ce87c7b492eff954dece91b (patch) | |
| tree | 143d3c779718ae42d646df63e738e9b3f88a5007 /src/lib | |
| parent | ccfea0444597a54638a991a413937f503039fd62 (diff) | |
Use nlohmann JSON library instead of rolling our own.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/http_server.cc | 12 | ||||
| -rw-r--r-- | src/lib/wscript | 2 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/http_server.cc b/src/lib/http_server.cc index 0ee62756a..73c2a6360 100644 --- a/src/lib/http_server.cc +++ b/src/lib/http_server.cc @@ -25,6 +25,7 @@ #include "http_server.h" #include "util.h" #include "variant.h" +#include <nlohmann/json.hpp> #include <boost/algorithm/string.hpp> #include <stdexcept> @@ -96,15 +97,14 @@ HTTPServer::get(string const& url) if (url == "/") { return Response(200, String::compose(dcp::file_to_string(resources_path() / "web" / "index.html"), variant::dcpomatic_player())); } else if (url == "/api/v1/status") { - auto json = string{"{ "}; + nlohmann::json json; { boost::mutex::scoped_lock lm(_mutex); - json += String::compose("\"playing\": %1, ", _playing ? "true" : "false"); - json += String::compose("\"position\": \"%1\", ", seconds_to_hms(_position.seconds())); - json += String::compose("\"dcp_name\": \"%1\"", _dcp_name); + json["playing"] = _playing; + json["position"] = seconds_to_hms(_position.seconds()); + json["dcp_name"] = _dcp_name; } - json += " }"; - auto response = Response(200, json); + auto response = Response(200, json.dump()); response.set_type(Response::Type::JSON); return response; } else { diff --git a/src/lib/wscript b/src/lib/wscript index ffab6404e..f9ee45ed5 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -252,7 +252,7 @@ def build(bld): BOOST_FILESYSTEM BOOST_THREAD BOOST_DATETIME BOOST_SIGNALS2 BOOST_REGEX SAMPLERATE POSTPROC TIFF SSH DCP CXML GLIB LZMA XML++ CURL ZIP BZ2 FONTCONFIG PANGOMM CAIROMM XMLSEC SUB ICU NETTLE PNG JPEG LEQM_NRT - LIBZ SQLITE3 + LIBZ SQLITE3 JSON """ if bld.env.TARGET_OSX: |
