From 8252a9e0046eacd0a2f1c435ff87d11030263371 Mon Sep 17 00:00:00 2001 From: cxh Date: Mon, 5 Jan 2026 10:31:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3json=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/serial_AT.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/serial_AT.cpp b/src/serial_AT.cpp index 5eb8f12..ced5653 100644 --- a/src/serial_AT.cpp +++ b/src/serial_AT.cpp @@ -9,6 +9,7 @@ #include "httplib.h" #include "logger.hpp" +#include "nlohmann/json.hpp" #include "serial_port.h" // ================== 全局 IMEI ================== @@ -67,18 +68,11 @@ void start_http_server(int port) std::string imei = get_imei(); - std::ostringstream oss; - oss << R"({ - "ok": true, - "server": { - "device_type": "tbox", - "imei": ")" - << imei << R"(", - "fw": "b-v2.1.0" - } - })"; + nlohmann::json j; + j["ok"] = true; + j["server"] = {{"device_type", "tbox"}, {"imei", imei}, {"fw", "b-v2.1.0"}}; - res.set_content(oss.str(), "application/json"); + res.set_content(j.dump(2), "application/json"); }); http_thread = std::thread(